Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7912975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:44:05+00:00 2026-06-03T13:44:05+00:00

I am building an iPhone app using jQuery Mobile, jQuery 1.7.2, and PhoneGap trying

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:44:06+00:00Added an answer on June 3, 2026 at 1:44 pm

    As jfriend00 says,

    A JSONP request does not use an actual ajax call where you can control the HTTP request.

    However in your case – the header you’re attempting to add being basic Authorization – you can just inject that into the URL, as you’d “usually” do. So to authenticate at http://example.com with the user “user” and password “pass”, the URL would be http://user:pass@example.com/.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a simple content app using PhoneGap + jquery mobile. My AdMob banner
I have an iPhone app accessing an ASP.NET Webservice for data. Since I'm building
I am building an iPhone App using PhoneGap. I am using ChildBrowser plugin. If
I'm building an iPhone app using Titanium Mobile and using the HTTPClient. Whenever I
I'm building an app that allows users to snap pictures using the iPhone camera,
I'm working on building an iPhone app with Titanium Mobile 1.0 and I see
I'm building an iPhone app that has to download an Excel (.xls) file from
I'm building a NSPredicate using the code below for an iPhone app. The logging
I am using jquery mobile in iPhone application, I have included the resources files
I am building an iphone app that reads a phone number from the address

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.