I’m trying to access rest service using ajax.
If I’ll paste this link on any web browser it will give a result like this:
{"SessionID":"a7f58a4a-f922-47c1-8351-d2035df4968c","SourceIP":"127.0.0.1","UserID":313}
(Link has changed for security)
https://thisisjustasample/Rest/Authenticate/Login?username=user&password=pass123&ip=127.0.0.1
But I found no luck to access the link using ajax:
A call from ‘View’ part:
getdata('https://thisisjustasample/Rest/Authenticate/Login?username=user&password=pass123&ip=127.0.0.1');
Function inside js file:
function getdata(url) {
$.ajax({
url: url,
type: 'GET',
contentType: 'application/json',
success: function (data) {
if (data) {
showtooltip(data);
}
},
error: function (xhr, ajaxOptions, error) {
showtooltip(xhr.status + ': ' + error);
}
});
}
It always return a ‘0’ status. And when I check my database, nothing has changed with the data. What is wrong with the code?
I have a feeling the problem is that you are specifying a content type of json when you shouldn’t specify a contentType, and your params should be part of data.