1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Ajax】phpで処理するAjaxを新規作成 

1
Last updated at Posted at 2019-07-31

備考欄

“success(),error(),complete()“はjQuery1.8~非推奨になったため、
代わりに“done(),fail(),always()“を使うように

自分用メモ

test.js
// jQuery 1.8~
$.ajax({
	url      : '../system/Ajax/change_switch.php',
	type     : 'POST',
	dataType : "json",
	data     : {
		id  : 'hoge',
		name: 'entry'
	}
})
// 成功
.done(function( data ) {
	console.log('成功');
})
// 失敗
.fail(function( data ) {
	console.log('失敗');
})
// 完了
.always(function( data ) {
	console.log('完了');
});
../Ajax/test.php
<?php
header('Content-Type: application/json');

$id   = $_POST['id'];
$name = $_POST['name'];
$data = ['データ',ture]; // この辺は好みで


echo json_encode($data);

【参考サイト】
【Ajax】通信が成功した時の処理「success」と「done」の違いについて - Qiita
[jQuery.ajax()のまとめ: 小粋空間]
(http://www.koikikukan.com/archives/2012/10/02-005555.php)

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?