I have a rest URL where I need to post some JSON data and it would give a response as below screenshot
Now I need to consume this in my application using $http or $.ajax.I used $.ajax as below
var postdata = {} //whole jsonobject which is der in above screenshot
$.ajax({
url: "http://10.11.13.153:8081/fro?assettype=00000000-0000-0000-0000-000000031026",
type: 'post',
data: postdata,
dataType: 'json',
success: function (data) {
console.log("response ",JSON.stringify(data));
}
});
But for this I get 200 response but I don't see that response consoled in success function.
In the network tab I see the below response
terms%5Bitems%5D%5B0%5D%5B_type%5D=term&terms%5Bitems%5D%5B0%5D%5B_id%5D=6662c0f2.e1b1ec6c.1mdln1e8h.0ibdeqc.s1nm3u.vbt90ta1civ5asp5qetu5&terms%5Bitems%5D%5B0%5D%5B_url%5D=https%3A%2F%2F10.11.13.155%3A9445%2Fibm%2Fiis%2Figc%2F%23dossierView%2F6662c0f2.e1b1ec6c.1mdln1e8h.0ibdeqc.s1nm3u.vbt90ta1civ5asp5qetu5&terms%5Bitems%5D%5B0%5D%5B_name%5D=Export_02
which is not in JSON format and not is not expected.
Below is the screenshot of headers in N/w tab
In my request headers why do I see form-urlencoded type?
I understood that it takes by default. Then how to change and make it take application/json?
Also as a try instead of JSON as datatype I changed as
datatype:'html'
Then this time I'm getting the same response as above, but this time it is getting consoled in success function. Why so? What can be done here to get the expected response in JSON format. Or anything headers that needs to be added at server side. Help or ideas please