//ページ取得(GET)
$(document).on('submit', '.フォーム名', function (event) {
let form = event.currentTarget;
//パラメータ全て
//let queryParam = $(form).serialize();
//パラメータ指定
//let queryParam = new URLSearchParams;
//queryParam.append('パラメータ名', 'パラメータ値');
const url = `コントローラ名/メソッド名?${queryParam.toString()}`;
$.ajax({
url: url,
type: 'GET',
timeout: 20000,
}).done(function (data) {
$('.追加対象').append(data);
}).fail(function (error) {
if (error.status.toString().length <= 4) {
console.log(`${error.status}:通信エラー`);
}
else {
console.log(`${error.status}:${error.responseText}`);
}
}).always(function () {
});
return false;
});
//ページ取得(POST)
//FromData
$(document).on('submit', '.フォーム名', function (event) {
let form = event.currentTarget;
//全て
//let requestArray = $(form).serializeArray();
//var fromData = {};
//$(requestArray).each(function (index, obj) {
// fromData[obj.name] = obj.value;
//});
//指定
//let fromData = {
// 'キー名': 'バリュー値',
// 'キー名': 'バリュー値'
//};
const url = `home/privacy`;
$.ajax({
url: url,
type: 'POST',
data: fromData,
timeout: 20000,
}).done(function (data) {
$('.追加対象').append(data);
}).fail(function (error) {
if (error.status.toString().length <= 4) {
}
else {
}
}).always(function () {
});
return false;
});
//ページ取得(POST)
//Json
$(document).on('submit', '.フォーム名', function (event) {
let form = event.currentTarget;
//全て
//let requestArray = $(form).serializeArray();
//var jsonParam = {};
//$(requestArray).each(function (index, obj) {
// jsonParam[obj.name] = obj.value;
//});
//指定
//let jsonParam = {
// 'キー名': 'バリュー値',
// 'キー名': 'バリュー値'
//};
const url = `home/privacy`;
$.ajax({
url: url,
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(jsonParam),
timeout: 20000,
}).done(function (data) {
$('.追加対象').append(data);
}).fail(function (error) {
if (error.status.toString().length <= 4) {
}
else {
}
}).always(function () {
});
return false;
});
More than 3 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme