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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:03:23+00:00 2026-05-29T06:03:23+00:00

After doing an AJAX call, am redirecting- using the following code. But, after AJAX

  • 0

After doing an AJAX call, am redirecting- using the following code. But, after AJAX completion, it gives Error alert; then its redirecting.

callService($serviceUrl, $serviceName, 'POST');             
//redirecting to nextpage
window.location.href = "nextPage.html";

function callService($serviceUrl, $serviceName, $method) {
  ......

  $.ajax({
    url : $serviceUrl,
    dataType : "json",
    type : $method,
    data : $requestData,
    success : function (data) {
        switch($serviceName) {
            case 'getTopRated':     populateTopRated(data);
                        break;
            case 'GetLatestScoop':  populateLiveScoop(data);
                        break;
            .....
        }
        $.mobile.pageLoading(true);
    },
    error : function(XMLHttpRequest, textStatus, errorThrown) {
        alert("Error");
        $.mobile.pageLoading(true);
    }
  });

}

Is there a way to resolve it without- modifying the 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-29T06:03:24+00:00Added an answer on May 29, 2026 at 6:03 am

    Wait until the ajax request complete before you redirect to another page. Since you redirect as soon as calling the service the request aborts and then error handler is triggered due to which you are seeing the alert message from error handler. Move the code to redirect inside ajax success callback it will work.

    function callService($serviceUrl, $serviceName, $method) {
      ......
    
      $.ajax({
        url : $serviceUrl,
        dataType : "json",
        type : $method,
        data : $requestData,
        success : function (data) {
            switch($serviceName) {
                case 'getTopRated':     populateTopRated(data);
                            break;
                case 'GetLatestScoop':  populateLiveScoop(data);
                            break;
                .....
    
    
                //redirecting to nextpage
                window.location.href = "nextPage.html";
            }
            $.mobile.pageLoading(true);
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            alert("Error");
            $.mobile.pageLoading(true);
        }
      });
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After doing an async $.ajax call, I need to highlight the table cell that
I have some problems with redirecting/reloading after a successful ajax call. Here is the
Context PHP 5.3.x Overview After doing a code-review with an associate who uses both
I'm getting a getaddress error and after doing some sleuthing, it looks like it
OK Ive written this neat javascript 'thing' using jquery and ajax. Its all based
I'm trying to refactor this code. I have this jquery ajax call $.ajax({ url:
After doing so: $.ajax({ type: POST, url: $(#form).attr(action), data: value= + value + &sel=
I'm doing an ajax call. The function called on success looks as follows: function(data){
Hey, I am doing to AJAX call to flickr.interestingness.getList to get the interesting pictures
I'm doing an AJAX call (regular JS) and, if it takes more than, say,

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.