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

  • Home
  • SEARCH
  • 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 6137093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:41:01+00:00 2026-05-23T17:41:01+00:00

I have a simple javascript that uses $.ajax() from JQuery which works great for

  • 0

I have a simple javascript that uses $.ajax() from JQuery which works great for GET/POST. However, for some users that are behind a proxy, they receive the 407 error as outlined in the post below.

407 Proxy Authentication Required

Now, as you will see, I’ve updated that post stating that the usage of JSONP will suffice as a workaround. Where I’m at now, is I don’t want to use JSONP all the time, only when it is required.

 function original() {
     $.ajax({
         url: "http://somecool.url/foo",
         data: { id:"bar"},
         statusCode: {
             407: foo()
         },
         success: function(data) {
             $.each(data, function(k,v) {
                 $('#foo').append("<li>" + k + ":" + v + "</li>");
             });
         }
     });
 }    


 function foo() {
     $.ajax({
         url: "http://somecool.url/foo",
         data: { id:"bar" },
         dataType: "jsonp",
         success: function(data) {
             $.each(data, function(k,v) {
                 $('#foo').append("<li>" + k + ":" + v + "</li>");
             });
         }
     });
 }

 $(document).ready(function() {
     original();
 });

Is it possible to persist the status of the first failure, which returns the 407 error when there is a proxy issue so that all subsequent requests do not go to the original() function and go to the foo() function?

  • 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-05-23T17:41:01+00:00Added an answer on May 23, 2026 at 5:41 pm

    My original answer (below) was dealing with function name override to accommodate the code in your question. However, there’s a better solution, since after all you only want to switch all requests to JSONP if and only if you receive a 407 response code.

    $.ajaxSetup() was designed to do exactly that:

    function original() {
        $.ajax({
            url: "http://somecool.url/foo",
            data: { id:"bar"},
            statusCode: {
                 407: function() {
                     $.ajaxSetup({ dataType: "jsonp" });
                     // Now all AJAX requests use JSONP, retry.
                     original();
                 }
            },
            success: function(data) {
                $.each(data, function(k,v) {
                    $('#foo').append("<li>" + k + ":" + v + "</li>");
                });
            }
        });
    }
    

    With this strategy, once 407 is received, all the future AJAX requests will use JSONP.



    For the sake of history, here is my original answer.

    You can permanently change the function stored in original when you receive a 407 response code for the first time:

    function original() {
        $.ajax({
            url: "http://somecool.url/foo",
            data: { id:"bar"},
            statusCode: {
                 407: function() {
                     window.original = foo;
                     foo();
                 }
            },
            success: function(data) {
                $.each(data, function(k,v) {
                    $('#foo').append("<li>" + k + ":" + v + "</li>");
                });
            }
        });
    }
    

    From then on, the name original will refer to foo(). You can even change the function and call its replacement at the same time:

    407: function() {
        (window.original = foo)();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple form that uses jQuery validation to notify the user of
I have a simple horizontal menu that uses JQuery to vertically slide down a
I have the following (fairly) simple JavaScript snippet that I have wired into Greasemonkey.
I am new to Ajax and have been following a tutorial from JQuery.com. I
I have an ajax function which call a servlet to get list of products
I am building a site that uses a simple AJAX Servlet to talk JMS
I have a contact us form that uses Ajax (i.e. relies on asynchronous requests).
I have some JavaScript that can appear on many different pages. Sometimes those pages
I have a simple ASP.NET page that uses the VLC media player to play
Does anyone use PhoneGap? I have a php app which uses ajax to receive

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.