javascript - jQuery not sending JSON on AJAX POST request -
i little confused here,i trying post data node js server using following code:
$.ajax({type:'post', url:'/map', data:'type=line&geometry='+str, success:function(msg) { console.log(msg); }, datatype:'json' }); this result here:
{ type: 'line', geometry: 'b~cqcge{b[mv|q@xnyc' } this not json.i had tried use contenttype , this:
$.ajax({type:'post', url:'/map', data:{type:'line',geometry:str}, success:function(msg) { console.log(msg); }, datatype:'json', contenttype:"application/json" }); even sent data without change.i have tried above method using data string first one.i have tried setting processdata false along methods in code blocks.
it important me data in json , use ajax because trying insert mongodb node js using mongojs , fails
actually datatype has nothing input rather output.
instead want stringify input data , send down single variable backend can decode it:
$.ajax({type:'post', url:'/map', data: {data: json.stringify({type: 'line', geometry: str})}, success:function(msg) { console.log(msg); }, datatype:'json' }); that way in backend decode data , should functioning object json.
note need json class this, jquery not include ability default: https://github.com/douglascrockford/json-js
Comments
Post a Comment