jquery在ajax调用中发送表单数据和json对象 [英] jquery sending form data and a json object in an ajax call
问题描述
我正在调用另一个ajax页面,该调用发布了一个json对象。
我还需要从
格式发送数据(不使用提交 - 我将ajax调用附加到使用 e.preventDeault()
调用方式如下:
var myUrl ='sendswatch-data.php';
$ .ajax({
url:myUrl,
data:{'swatchid []':swatchArray},'formdata':$('#orderData')。serialize()},
类型:POST,
错误:函数(xhr,statusText,errorThrown){
//计算出错误并显示相应的消息
},
成功:函数(myData){
$('#tabsampleorder')。html(myData);
$('。tabber')。hide();
$('# tabsample)')。show();
}
});
我在formdata的页面id上有一个表单。
我如何发送这个以及json对象?我试过了:
$ b $ pre $ data:{'swatchid []':swatchArray},'formdata':$('#orderData' ).serialize()},
但是会产生一个错误。
在watchArray之后有一个额外的}。尝试删除它。
data:{'swatchid []':swatchArray,'formdata':$('#orderData') .serialize()},
I'm making a call to another ajax page, the call posts a json object.
I also need to send data from a form
(not using submit - I have the ajax call attached to a button which uses e.preventDeault()
).
The call is as folows:
var myUrl = 'sendswatch-data.php';
$.ajax({
url: myUrl,
data: {'swatchid[]':swatchArray}, 'formdata':$('#orderData').serialize()},
type: "POST",
error: function(xhr, statusText, errorThrown){
// Work out what the error was and display the appropriate message
},
success: function(myData){
$('#tabsampleorder').html(myData);
$('.tabber').hide();
$('#tabsampleorder').show();
}
});
I have a form on the page id of formdata.
How do I send this as well as the json object? I've tried
data: {'swatchid[]':swatchArray}, 'formdata':$('#orderData').serialize()},
but that's generating an error.
You have an extra } after watchArray. Try removing that.
data: {'swatchid[]':swatchArray, 'formdata':$('#orderData').serialize()},
这篇关于jquery在ajax调用中发送表单数据和json对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!