Jquery Ajax Posting json to webservice

后端 未结 6 557
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 06:15

I am trying to post a JSON object to a asp.net webservice.

My json looks like this:

var markers = { \"markers\": [
  { \"position\": \"128.3657142857         


        
6条回答
  •  执念已碎
    2020-11-22 06:38

    I have encountered this one too and this is my solution.

    If you are encountering an invalid json object exception when parsing data, even though you know that your json string is correct, stringify the data you received in your ajax code before parsing it to JSON:

    $.post(CONTEXT+"servlet/capture",{
            yesTransactionId : yesTransactionId, 
            productOfferId : productOfferId
            },
            function(data){
                try{
                    var trimData = $.trim(JSON.stringify(data));
                    var obj      = $.parseJSON(trimData);
                    if(obj.success == 'true'){ 
                        //some codes ...
    

提交回复
热议问题