I am building an iPhone app using jQuery Mobile, jQuery 1.7.2, and PhoneGap
trying to get a JSONP from ASP.NET RESTful web service using this code, problem that I need to authenticate first and get a token, then send it back again.
here is my function:
var setToken = function () {
var serverToken = '';
$.support.cors = true;
jQuery('body').ajaxSend(function (evt, xhr) {
xhr.setRequestHeader("Authorization", "Basic " + $.base64.encode(username + ":" + password));
xhr.setRequestHeader('X-Accept', 'application/json');
});
$.getJSON(url + "?jsoncallback=?", null, function (res) {
console.log(res);
serverToken = res.Token;
});
$('body').ajaxSend(function (evt, xhr, ajaxOptions) {
xhr.setRequestHeader('NewToken', serverToken);
});
};
I get 401 (Unauthorized) checked the header:
Request URL:http://192.168.0.44/call/?jsoncallback=jQuery17206244203052483243499_132336710607307&_=1336742104278
Request Method:GET
Status Code:401 Unauthorized
Request Headers
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Host:192.168.0.44
Referer:http://localhost/myMobileApp/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19
Query String Parametersview URL encoded
jsoncallback:jQuery17206244203052483243499_132336710607307
_:1336710704278
Response Headers
Access-Control-Allow-Origin:*
Cache-Control:private
Content-Length:0
Date:Fri, 11 May 2012 04:31:52 GMT
Server:Microsoft-IIS/7.5
WWW-Authenticate:Basic
X-AspNetMvc-Version:3.0
X-Powered-By:ASP.NET
setRequestHeader did not add the headers.
what am I doing wrong?
keep in mind that the server side was set up already to return JSONP, I don't think we need to make changes there, but any thoughts would help
thanks in advance