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 919545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:33:47+00:00 2026-05-15T18:33:47+00:00

A quick question of perhaps a more speculative nature. I’ve been getting heavy into

  • 0

A quick question of perhaps a more speculative nature. I’ve been getting heavy into jquery lately to handle all the ajax in my web apps.

Right now I’m building a bidding system in PHP that makes heavy use of mod_rewrite. I’m using jQuery with a confirm dialog to send an Ajax request that will spend some of the user’s predeposited credits on a bid. The ajax request to spend is sent with the cost as a post parameter to a PHP controller that spends the users credits and then echos the output, which jQuery then places back into the document.

It’s working fine, but what I’m wondering is if there is a better way to make jQuery handle the refusal of the purchase if the user has insufficient credits. Right now I have the php answering with an echo that displays this message with a link to the make a deposit page… but I’d rather have a redirect happen automatically.

Is there some way my jQuery script could be notified with the boolean of success or failure before .load finishes, and then redirect in the case of failure? Possibly through HTTP headers determining the handling? The only way I could think of is to place a true or false in an html element that gets check in the callback after .load() and in the case of a false perform a redirect.

Thanks and sorry for the explanation length.

  • 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-15T18:33:48+00:00Added an answer on May 15, 2026 at 6:33 pm

    Use the lower level $.ajax call to have full maximum control over the request. Ideally, instead of sending a success 2xx response, send an error response which will automatically get sent to your error callback.

    $.ajax({
        url: '..',
        success: function() {
            // if it gets here, then assume credits were used
        },
        error: function() {
            // some error happened
            // if error was about insufficient funds, then redirect
        }
    });
    

    From the server, send the success response as you are doing right now. However for errors, change the response header, and send a JSON object or plain text indicating what the error was. And there is a header for exactly what you are looking for. It’s 402 - Payment Required 🙂

    header('HTTP/1.1 402 Payment Required');
    

    send a JSON object as response with more details:

    {
        status: 'error',
        reason: 'Insufficient Funds',
        balance: '$2.78',
        amountRequested: '$3.50'
    }
    

    For the updated comment, you need to use a closure (better than global variables 🙂
    Suppose the outer function gets the element name/ID, wraps that value through a closure in the success callback. Please let me know if this is not what you intended.

    function makeAJAXCall(elementName) {
        $.ajax({
            success: function(...) {
                // elementName is available here through a closure
                alert(elementName);
            }
        });    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question about WordPress. I've been Googling all over the place and cannot find
Quick, and perhaps silly question, but here it is nevertheless. Writing to a register
Quick question: How can I use good, old jQuery Validate to validate a form
quick question. I just downloaded Visual Studio 11 Developer Preview but all tutorials to
Quick question (and sorry if it's already been asked, I have looked but couldn't
Quick question: how do i detect if a tap gesture recognizer is within a
Quick question that I can't seem to find an answer for. If I am
quick question. I'd like to remove the sup tag from the following string, and
Quick question about OpenMP: I'm not sure how to implement a nested double for
Quick question - if a textfield in a webform, does not automatically has the

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.