我如何发送使用jQuery的阿贾克斯后的阵列? [英] How do I send an array in an .ajax post using jQuery?
本文介绍了我如何发送使用jQuery的阿贾克斯后的阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经通过一个简单的数据收集循环,将其推到一个数组。我再尝试了数组发送到页面的方法(的.aspx)。有一些事情,它并没有像我想的阵列。这是我的code:
对于提交到服务器 //包装表数据
$(#saveToDB)。点击(函数(){
VAR dataForSubmit =新的Array();
//收集所有数据阵列,除了删除单元,.rowToDelete
$('#QueueTable TBODY TD:没有(.rowToDelete))各(功能(){。
dataForSubmit.push($(本)的.html());
});
//测试阵列
//警报(dataForSubmit);
//发送阵列的方法
$阿贾克斯({
键入:POST,
网址:DailyReceipts.aspx /保存数据,
的contentType:应用/ JSON的;字符集= UTF-8,
数据类型:JSON,
数据:dataForSubmit,
成功:函数(MSG){
$ .jGrowl('您的资料已成功保存。{标题:重要的});
$('#结果)。追加(msg.d)
},
错误:函数(){
$ .jGrowl('发生错误的保存数据。{标题:重要的});
}
});
});
解决方案
只是附加任何参数,它希望在这样的数据参数:
数据:paramName配置=+ dataForSubmit,
,或者:
数据:{paramName配置:dataForSubmit},
I have looped through a simple gathering data and pushing it into an array. I am then trying to send that array to a page method (.aspx). There is something about the array that it does not like I think. Here is my code:
//packaging table data for submit to server
$("#saveToDB").click(function() {
var dataForSubmit = new Array();
//gather all data to array except the "delete" cell, .rowToDelete
$('#QueueTable tbody td:not(.rowToDelete)').each(function() {
dataForSubmit.push($(this).html());
});
//test the array
//alert(dataForSubmit);
//send array to method
$.ajax({
type: "POST",
url: "DailyReceipts.aspx/saveData",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: dataForSubmit,
success: function(msg) {
$.jGrowl('Your data has been successfully saved.', { header: 'Important' });
$('#result').append(msg.d)
},
error: function() {
$.jGrowl('An error has occured in saving the data.', { header: 'Important' });
}
});
});
解决方案
Just append whatever parameter it's expecting on the data argument like this:
data: "paramName=" + dataForSubmit,
or, alternatively:
data: { paramName : dataForSubmit },
这篇关于我如何发送使用jQuery的阿贾克斯后的阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文