Karem
Karem

Reputation: 18123

jQuery ajax call wont work

I have this:

$('.photoSaved').click(function () {
  var savedPhoto = $(this).attr('id');
  $.ajax({
    url: "status.php",
    type: "POST",
    data: { mode: 'use', name: savedPhoto },
    success: function(){
      $.fancybox.close();
      $('#status_upContent').hide();
      $("#image").append($(document.createElement("img")).attr({src: "images/users/status/"+savedPhoto})).show();
    }
  });
});

with:

if($_POST['mode'] && $_POST['mode'] == 'use'){
  $_SESSION['status_attachedImage'] = $_POST['name'];
  echo 'ok';
}

I can see it make the request, but it doesnt give me the response "ok" and the success: doesnt execute

Upvotes: 0

Views: 189

Answers (2)

Alexander Wallin
Alexander Wallin

Reputation: 1394

If you are developing in Firefox or Safari you may use the console.error function to debug any error thrown in your code.

Upvotes: 1

hunter
hunter

Reputation: 63562

try adding the "error" callback. This will show you what is going wrong.

error(XMLHttpRequest, textStatus, errorThrown)

A function to be called if the request fails. The function is passed three arguments: The XMLHttpRequest object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "notmodified" and "parsererror". This is an Ajax Event.This handler is not called for JSONP requests, because they do not use an XMLHttpRequest.

So add in this line, similar to your success callback:

error: function(XMLHttpRequest, textStatus, errorThrown) {
    console.error(errorThrown);
} 

Upvotes: 2

Related Questions