Tomer Gal
Tomer Gal

Reputation: 969

jQuery $.ajax is not doing anything

I have a jQuery AJAX request that does not seem to be doing anything.

I see no action on the Network tab on Chrome Debugger,

The error/success callbacks are not being called inside the function and nothing seem to happen on the server side whatsoever.

The thing is, this is not happening on my main local domain: http://dev.sitename.com

It only happen on my inner pages, for example: http://dev.sitename.com/about

My guess is there is some .htaccess rule that is damaging the process but I see no Network activity what so ever, so how could it be?

Here's my code:

$.ajax({
    url: 'ajax.php?cachekiller=' + (new Date()).getTime(),
    data: {
        action: 'doLogin'
    },
    success: function() {
    // Not being called
    },
    error: function() {
    // Not being called either
    }
});

Thank you

Upvotes: 0

Views: 1452

Answers (3)

Rafay
Rafay

Reputation: 31033

OK every thing seems to be fine, here are a few things that you can check out

  1. (might seem outrageous) have you included the jQuery.js
  2. make sure that the jQuery.js is included before any other js file
  3. put a / before the url like and make sure that you have placed the ajax.php at the root of your server
  4. as mentioned in the comments check for any js errors in the firebug console(firefox) or chrome developer tools
$.ajax({
        url: '/ajax.php',
        cache:false,
        data: {
            action: 'doLogin'
        },
        success: function() {
        // Not being called
        },
        error: function() {
        // Not being called either
        }
    });

you dont need to use cachekiller use cache:false prop of ajax method

Upvotes: 1

Jaroslav Trsek
Jaroslav Trsek

Reputation: 51

try this:

$.ajax({
  url: 'ajax.php',
  cache: false,
  data: {
      action: 'doLogin'
  },
  success: function(data) {
      console.log(data);
  },
  error: function() {
      console.log('error');
  }
});

and in ajax.php script:

header("Pragma: no-cache");
header("Cache-Control: must-revalidate");
header("Cache-Control: no-cache");
header("Cache-Control: no-store");
header("Expires: 0");

Upvotes: 4

Gil LB
Gil LB

Reputation: 824

try putting cachekiller on data param

$.ajax({
    url: 'ajax.php',
    data: {
        cachekiller: (new Date()).getTime(),
        action: 'doLogin'
    },
    success: function() {
    // Not being called
    },
    error: function() {
    // Not being called either
    }
});

Upvotes: 2

Related Questions