我正在调用另一个ajax页面,该调用发布了一个json对象。
我还需要从表单发送数据
(不使用提交 - 我将ajax调用附加到使用e.preventDeault()
)的按钮。
电话如下:
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();
}
});
我在formdata的页面ID上有一个表单。
如何发送此以及json对象?我试过了
data: {'swatchid[]':swatchArray}, 'formdata':$('#orderData').serialize()},
但是这会产生错误。
答案 0 :(得分:5)
在watchArray之后你有一个额外的}。尝试删除它。
data: {'swatchid[]':swatchArray, 'formdata':$('#orderData').serialize()},
答案 1 :(得分:2)
您可以按如下方式从表单发送数据:
data : { swatchid: swatchArray, formdata: $('#orderData').serialize() }
您需要在控制器中为您添加的每个字段添加一个参数。