开发者

Parse Error when trying to send JSON using JQuery Ajax()

I am trying to send the following json to we开发者_JAVA技巧b method. Firebug reports the following error:

XML Parsing Error: no element found Location: moz-nullprincipal:{d9dc6bef-4ec9-4899-b8df-7319db0e47cf} Line Number 1, Column 1:

I am editing the request header to include the content-type. Can someone help me out??

  var request = {"uid":"Test","application":",myApplication","localization":"en-us","id":"aae49326","context":"","clientToken":"puttokenhere2","version":"2.0.87","timestamp":"4/6/2011 13:15:57","status":"COMPLETED","data":""};
        jQuery.ajax({ beforeSend: function(xhrObj) {
            xhrObj.setRequestHeader("Method", "POST");
            xhrObj.setRequestHeader("Content-Type", "application/json; charset=\"utf-8\";");
        },            
            async: false,
            type: "POST",
            contentType: "application/json; charset=\"utf-8\";",
            dataType: "json",
            url: MILESTONEURL,
            data: request,
            complete: function(response, status) {
                if ("success" == status) {
                    alert("SUCCESS:\n" + response.responseText);
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                var response = eval("(" + XMLHttpRequest.responseText + ')'); ;
                alert("FAILED:\n" + XMLHttpRequest.responseText);
            }
        });
 }

The problem was at the webservice - closing


on Line 1 the keys shoudln't have double quotes

try this:

   var request = {uid:"Test",application:",myApplication",localization:"en-us",id:"aae49326",context:"",clientToken:"puttokenhere2",version:"2.0.87",timestamp:"4/6/2011 13:15:57",status:"COMPLETED",data:""};
    jQuery.ajax({ beforeSend: function(xhrObj) {
        xhrObj.setRequestHeader("Method", "POST");
        xhrObj.setRequestHeader("Content-Type", "application/json; charset=\"utf-8\";");
    },            
        async: false,
        type: "POST",
        contentType: "application/json; charset=\"utf-8\";",
        dataType: "json",
        url: MILESTONEURL,
        data: request,
        complete: function(response, status) {
            if ("success" == status) {
                alert("SUCCESS:\n" + response.responseText);
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            var response = eval("(" + XMLHttpRequest.responseText + ')'); ;
            alert("FAILED:\n" + XMLHttpRequest.responseText);
        }
    });
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜