1

我已经使用了这个基本的、简化的 ajax 脚本一百次了,现在我一直在思考这次它有什么问题,为什么我没有得到回应:

$('#btn-submit').click(function() {

var str = $("#form-submit").serialize();
alert(str); //alert pops up

$.ajax({
  type: "POST",
  url: "ajax-submit.php",
  data: str,
  success: function(msg) {
      alert(msg); //does not show
      if(msg==0) {
            alert(0); //does not show
          }
      }
});

alert('i come after ajax'); //alert pops up
});

此脚本之前包含 jQuery 文件,并且路径正确(仔细检查,firebug 中没有错误)。

ajax-submit.php 的路径也可以,内容是<?php echo "test"; ?>.

有谁知道为什么这不起作用?

4

1 回答 1

0

我终于发现了一个非常愚蠢的错误:我使用type="submit"了按钮,所以每次在调用ajax之前都提交了表单......

于 2012-09-28T19:30:34.880 回答