遷移しないのであればやり方は2つ
- ajaxでバックグラウンドに送信
- 別ウィンドに送信
(new window、target=_blank、frame、iframeなど)
sample
sample追記します
HTML
1<div class="submit"><button type="button" name="mode" value="confirm"><img src="images/check.png" alt="送信"></button>
javascript
1$(function(){
2 $('.submit button').on('click',function(e){
3 e.preventDefault();/* typo調整*/
4 $.ajax({
5 url: '/sample/index',
6 type: 'GET',
7 data: formData,
8 timeout: 10000,
9 dataType: 'text'
10 }).done(function(data){
11 console.log(data);
12 });
13 });
14});
※formDataは別途用意するものとする
追記
適当なフォームからデータをもらってform外のボタンをおしてajax送信
javascript
1$(function(){
2 $('.submit button').on('click',function(e){
3 e.preventDefault();
4 $.ajax({
5 url: '/sample/index',
6 type: 'GET',
7 data: {
8 hoge:encodeURIComponent($('#f1 [name=hoge]').val()),
9 fuga:encodeURIComponent($('#f1 [name=fuga]').val()),
10 },
11 dataType: 'text',
12 }).done(function(data){
13 console.log(data);
14 }).fail(function(xhr,err){
15 console.log(err);
16 });
17 });
18});
19</script>
HTML
1<form id="f1">
2<input type="text" name="hoge" value="1">
3<input type="text" name="fuga" value="漢字">
4</form>
5
6<div class="submit"><button type="button" name="mode" value="confirm"><img src="images/check.png" alt="送信"></button>
POST処理
javascript
1$(function(){
2 $('.submit button').on('click',function(e){
3 e.preventDefault();
4 $.ajax({
5 url: '/sample/index',
6 type: 'POST',
7 data: new FormData($('#f1').get(0)),
8 dataType: 'text',
9 cache:false,
10 processData: false,
11 contentType: false,
12 }).done(function(data){
13 console.log(data);
14 }).fail(function(xhr,err){
15 console.log(err);
16 });
17 });
18});
19</script>
で送って、受け取り側は
PHP
1$name=filter_input(INPUT_POST,"name");
のような処理です。
受け取り側
※仮にpost処理だとします
PHP
1<?PHP
2$name=filter_input(INPUT_POST,"name");
3if(!is_null($name){
4 print htmlspecialchars($name);
5 exit;
6}
7?>
8HTML部分
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/05 03:32
2018/03/05 03:47
2018/03/05 03:54
2018/03/05 05:23
2018/03/05 05:42
2018/03/05 07:34
2018/03/05 07:53
2018/03/05 08:16
2018/03/05 08:22
2018/03/05 08:36