I am submitting a post request with data type json.
I am able to see json response in fiddrel but jquery is not able to parse that.
Here is my code:
$("#jsonTestCasePost").click(function(){
var requestType = $("#requestType").val();
$('#result').val(requestType);
debugger;
$.post("http://localhost/api/number/substract", {numberA:"32",numberB:"10"},
function(data){
debugger;
$('#result').val(data);
}, requestType);
});
This is my raw response text in fiddler.
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 15
Server: Jetty(6.1.11)
{"result":"22"}
In jquery done function I see following values:
status: 0
statusTex: "",
responses: {}
headers: ""
Any idea what am I doing wrong here?
Thanks
As requested, here’s my comment in the form of an answer:
You are probably falling victim to restrictions due to the same origin policy. Make sure your request is being sent to the same server your page is on. Eg, if you are requesting
http://localhost/api/number/substract, your current requesting page must be athttp://localhost.