Forum Discussion
samudhraa
11 years agoExpert
Hi Shalini,
Few things that might be of help.
- I would recommend you to test the RESTcall using a REST client (chrome plugin , poster etc) , so that you would know the api , query parameters , data that should be given.
- I can see that you are authenticating , with a GET call , which is usually not the case. Generally , a POST call is used for authentication.
- Having said that , if you are doing a cross domain call , and handling it with jsonp , that would work only for GET call and not a POST call. You might have to think of an alternate solution for it. My suggestion would be , if you have control over the other end , to add the "access control allow origin" to the header of the method on server side.
Here is a sample ajax POST call that worked for me.
$.ajax({
url: 'http://blabla.k2.com/doSomething/',
type: 'POST',
data: data,
cache: false,
dataType: 'json',
processData : false, // Don't process the files
contentType: false, // Set content type to false as jQuery will tell the server its a query string request
success: function (data) {
console.log(data.UploadStatus);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log('Error is :' + errorThrown + '; ' + textStatus + '; ' + jqXHR.status);
}
});
I am sure you must have gone through this informative article on working with endpoints , but just in case.
Hope that helps.
Thanks,
Sam
- Telstra111 years agoGuideHi Sam,
I have added the other server to my list of Acceptable domains. and from my chrome plugin i can access the other domain and can get the JSON results back.
but when i implement the below code in and run through Endpoint,
$.ajax({
type: "GET",
url: "https://test.lithium.com/api/v1/workqueues?callback=?",
data: {
includeQueueBacklog: 'true',
jsonResult: 'true'
},
dataType: 'json',
success: function(jqXHR) {
alert("Success " + jqXHR.UploadStatus);
},
error: function(jqXHR) {
alert("Error " + jqXHR.status);
}
});
i get the results back in my network tab, status is 200 OK. but always goes to the Error message and cant read the output json.
error says "Call back jquery_000000<number> was not called".
any help much appreciated.
thanks,
Shalini.