开发者

Jquery post > success not trigger

I had a problem with jquery's post api.

   $(".MGdi").click(function () { 
      id=$(this).attr("rel")
      $.post( 'Mdeger.asp?cmd=MG', { id: id, drm: $(this).html()} ,
      function( data ) {
          var $response=$(data);
               var snc = $response.find('#snc').html();
          alert(snc);
      },"application/x-www-form-urlencoded");  
    });

Another way is:

$(".Pasif").click(function () { 
  id=$(this).attr("rel")
  $.post( 'Mdeger.asp?cmd=Pasif', { id: id, drm: $(this).html()} ,
  function( data ) {
      $(this).html(data);
      alert(data)
  },"application/x-www-form-urlencoded");
});开发者_如何学JAVA

Everything is OK on serverside but clientside's success function does nothing. Even basic codes like alert("hoho"); success not triggering.


this usually happens when respond couldn't be parsed. you should check the respond using firebug or similar debugging tool.

especially the methods that expects json data, strictly validates the respond and if there is anything invalid it just does nothing, no-error, no-warning, no-exception.

when your callback function doesn't run, you should suspect that your respond isn't correct.

// Türkçe özet

uzun lafın kısası dönüş değerinde bir terslik varsa dönüş fonksiyonu çalışmayacaktır. sunucudan gelen değerleri iyice kontrol etmekte fayda var. jquery dönüş değerinde veya dönüş fonksiyonunda bir hata olursa seni uyarmadan işi sonlandırıyor.


I had this problem as well. It turns out I was making an AJAX call to the same domain, but on a different port, which is not allowed (for security reasons) in Javascript.

See this relevant question for more info:

How do I send an AJAX request on a different port with jQuery?

I was very surprised that the AJAX call would POST/GET to the server, (which I was able to verify by looking at the server log) but that the response was never read. I would have thought that both sending and receiving would be disallowed.


I had this error too, and that was a stupid problem : I set dataType to "json" in my JS, but the page called was returning plain HTML. And this cause to not fire the success function at all.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜