user744621
user744621

Reputation: 147

AJAX don't wait for response

I have a webpage that has a simple AJAX request on page load:

$(document).ready(function() {
    $.get("ajax.php?do=something", function(response) {
        alert('response');
    });
});

This request takes about 15 seconds on my local test machine. The ajax.php does use session_start(), but calls session_write_close() straight after (almost straight after - it is called before any of the intensive processing is done):

<?php
session_start();

if(empty($_GET['do']))
    die("!Invalid request.");

$do = $_GET['do'];

if($do=="something-else")
{
}
else if($do=="something")
{
    session_write_close();

    $customerId = $_SESSION['customerId'];

    //processing done here
}
?>

The problem is the once this page loads, the AJAX is fired, but then if the user clicks on a link to go to another page, the browser waits for 15 seconds and then redirects.

I want to let the user go to other pages without having to wait, or if they stay, i want them to see the response.

EDIT Just to clarify it a bit more. Every page has a session_start() at the top, including the one that the user is trying to go to.

I am using the session in the ajax.php, and have edited the original question to reflect this.

Upvotes: 0

Views: 913

Answers (1)

Johnny Harlamert
Johnny Harlamert

Reputation: 271

Where is the link that is being clicked? Where does the link point to and how does it tie in with the AJAX you have posted? From what I see the AJAX worked as expected. You are not doing anything with sessions so you might as well not have any session start or close.

I would post this as a comment but it wont let me therefore I am giving this as an answer until you can give more details.

Upvotes: 0

Related Questions