Reputation: 398
I have one simple DataSnap server and i having trouble consuming the Json data on .ajax function by JQuery.
This is my code:
$.ajax({
url: "http://localhost:53383/datasnap/rest/TServerMethods1/ReverseString/logo",
headers: {"Accept": "application/json",
"Content-Type": "text/plain;charset=UTF-8",
"If-Modified-Since": "Mon, 1 Oct 1990 05:00:00 GMT",
"Pragma": "dssession="+pragma,
"Authorization": "Basic YWRtaW46MTIz"},
success: function(data) {
alert(data);
}
});
The function works, but when i send headers for the DataSnap authentication ("Authorization": "Basic YWRtaW46MTIz") JQuery make two requets, one 401 (Not authorised) and other ok. How this happend? I make one only request.
Upvotes: 0
Views: 747
Reputation: 3955
Try requesting Auth before actually sending a request:
beforeSend: function(req) {
req.setRequestHeader("Authorization": "Basic YWRtaW46MTIz");
}
I'm not sure if this solves the problem, but it's worth a try.
Upvotes: 1