ajax to get data from server--aData is undefined

ajax to get data from server--aData is undefined

little_heroinelittle_heroine Posts: 6Questions: 0Answers: 0
edited April 2012 in General
At the begining, i use simply jquery1.7 and ajax, by posting key/value data to the server and it woks well to response me with the data i need.
the code is like this:
[code]
$.ajax({
type:"post",
url:"/hosts",
data: JSON.stringify(paras),
contentType:"application/json; charset=ut-8",
datatype:"json",
success:function(){
Refresh_hosts();
}
});
[/code]
here JSON.stringify(paras)will make my paras look like this{name:"name",address:"address",comment:"comment"},
and i got my data:
[code]
[{"name":"host1","comment":"ok1","address":"123.234.0.1"},{"name":"host2","comment":"ok2","address":"123.234.0.2"},{"name":"host3","comment":"ok3","address":"123.234.0.3"},{"name":"host4","comment":"ok4","address":"123.234.0.4"}]
[/code]
now i am using datatables to get data from my server. code like this:
[code]
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push({ "name":"name","value": "name"},{"name": "adresss","value": "adresss"},{"name": "comment","value": "comment"});
$.ajax({
"dataType": "json",
"type": "POST",
"url": '/hosts',
"data": aoData,
"success": function(){myFunc();},
"error":function(XMLHttpRequest, textStatus, errorThrown){alert(XMLHttpRequest);}
});
}
[/code]

then here got the error,and i cannot get my data. i test it with firebug and saw that aoData i post to server is not like the data i used to post. there are many other information and the data is in fact not key:value format ,but { "name":, "value":}, is this the reason i got error?

or i test it step by step, and find out

[code]
var aData = fnDataSrc( json );
in the dom i can see:
aaData:
[["a", "b", "b", 4 more...], ["ad", "sdf", "sf", 4 more...], ["af", "xg", "gx", 4 more...], 7 more...]

0
["a", "b", "b", 4 more...]

1
["ad", "sdf", "sf", 4 more...]

2
["af", "xg", "gx", 4 more...]

3
["d", "f", "f", 4 more...]

4
["dg", "gf", "s", 4 more...]

5
["fdg", "dg", "fd", 4 more...]

6
["gf", "gd", "d", 4 more...]

7
["host1", "b", "b", 4 more...]

8
["host2", "a", "a", 4 more...]

9
["vcb", "bc", "bc", 4 more...]

mSource
"aaData"
toString
function()
[/code]
This discussion has been closed.