开发者

jQuery ajax call wont work

开发者 https://www.devze.com 2023-02-03 20:18 出处:网络
I have this: $(\'.photoSaved\').click(function () { var savedPhoto = $(this).attr(\'id\'); $.ajax({ url: \"status.php\",

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 requ开发者_如何学JAVAest, but it doesnt give me the response "ok" and the success: doesnt execute


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);
} 


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号