Php 无法使用AJAX发送POST请求

Php 无法使用AJAX发送POST请求,php,jquery,ajax,Php,Jquery,Ajax,我无法使用AJAX向我的php文件发送POST请求。我有两个文件,第一个是index.php,第二个是isVerificationStatusAPIV2.php。index.php的内容包括: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Phone Verification by Dial2Verify API V2

我无法使用AJAX向我的php文件发送POST请求。我有两个文件,第一个是index.php,第二个是isVerificationStatusAPIV2.php。index.php的内容包括:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Phone Verification by Dial2Verify API V2 ( www.dial2verify.com )</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
var attempt=1;
var transactionToken="";

    $(document).ready(function(){
        $("#enter_number").submit(function(e) {
         e.preventDefault();
         initiateDial2Verify();
        });
    });

    function initiateDial2Verify() {
        showCodeForm(1); 
        GetVerificationImage();
    }

    function showCodeForm(code) {
        $("#dial2verify").fadeIn();
        $("#enter_number").fadeOut();
        $("#waiting_msg").text("Waiting for missed call from "+$("#phone_number").val());
    }

    function GetVerificationImage() {
        $.post("GetImageAPIV2.php", { phone_number : $("#phone_number").val() }, 
               function(data) { updateImage(data.img,data.transactionToken); }, "json");
    }



    function updateImage(img, vtransactionToken) {




                             $("#Image").html("Please give a missed call to <br><img src=\""+img+"\"/>");

                         transactionToken = vtransactionToken;
                         PollStart("0");
                            }


    function CheckStatus()
    {
        $.post("VerificationStatusAPIV2.php", { transactionToken : transactionToken }, 
               function(data) { PollStart(data.status); }, "json");
    }


    function PollStart(vStatus)
    {
                     attempt =attempt+1;
                     if ( attempt >= 90  ) { TimeoutCheck(); }  
                     else
                     if (vStatus === "0") { 
                        $("#status").html("Please give a missed call in  <b><i>"+(90-attempt) +"</i></b> seconds.");
                        setTimeout(CheckStatus, 1000);
                        }                        
                     else if (vStatus === "1")
                    {
                    success(); 
                    }
                    else
                    TimeoutCheck();

    }


            function Err() {
            $("#status").html("Error!<br>Sorry something went wrong, Please cross check your telephone number."); 
            }

    function success() {
        $("#status").text("Congrats !!! Phone Number Verified!");

    }

    function TimeoutCheck() {
        $("#status").text("Verification Failed!");
    }

</script>
</head>
<body>
<form id="enter_number">
    <p>Enter your phone number:</p>
    <p><input type="text" name="phone_number" id="phone_number" /></p>
    <p><input type="submit" name="submit" value="Verify" /></p>
</form>

<div id="dial2verify" style="display: none;">
    <p id="waiting_msg"></p>
    <p id="Image">Loading ..</strong></p>
            <p id="status">Loading ..</strong></p>
</div>
</body>
</html>
在function CheckStatus中,我使用AJAX向文件VerificationStatusAPIV2.php发送post请求,但它没有发出任何post请求。有人能说出这是怎么回事吗


更新我刚刚看到数据中的状态。func CheckStatus中的状态为黄色,而其他状态为蓝色。也许这就是问题所在?

在你的代码中,你唯一有CheckStatus exept的地方就是这一行。。。setTimeoutCheckStatus,1000;因此,如果这是函数调用,它应该是这样的:setTimeoutCheckStatus,1000

这可能是您的问题。

尝试更改 到

在js中:

$("#btn_enter").submit(function(e) {
     e.preventDefault();
     initiateDial2Verify();
    });
您将提交函数指向HTML表单的ID

var request=$.ajax({
   method:"POST",
   url:"VerificationStatusAPIV2.php",
   data:{ transactionToken : transactionToken },
   dataType:"json"
  });
request.success(function(data){
  PollStart(data.status);
});

如果不使用您试图阻止的提交功能,而是单击后启动相关功能,不是更好吗?@RoyalBg是的,但我的问题是我无法在CheckStatus功能中发送post请求。这不是我的问题。我说我不能在CheckStatus://Sebastien.beaulie中发送post请求SetTimeout函数不需要括号,但我确信我使用相同的代码用于其他目的。相反,我在checkstatus中使用data.message。这次我使用的是data.status。另外,我的编译器用黄色显示状态,其他东西用蓝色显示,这可能是问题所在吗?你确定你正在按原样处理你的php页面吗?试着打印AJAX调用状态