PHP通过curl_exec执行的Ajax请求不起作用

问题描述 投票:0回答:1

我正在通过curl_exec执行php文件

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "MyFILE.php");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $o = curl_exec($ch);
    curl_close($ch);

在MyFILE.php中有一个ajax请求

    <script> jQuery.ajax({
        url: "http://localhost/AjaxFile.php",
        type: "POST",
        data : {data: "someData"},
        success: function(result){

        }
    }); </script>

但是对http://localhost/AjaxFile.php的请求未执行。我将仅在本地主机中使用它。

php-curl
1个回答
0
投票

希望对您有帮助。

<form id="idForm" method="post">
    <button type="submit" name="submit">Submit</button>
</form>
   <script> 
 $("#idForm").submit(function(e) {
    e.preventDefault(); // avoid to execute the actual submit of the form.
    $.ajax({
           type: "POST",
           url: 'AjaxFile.php',
           data: {data: "someData"}, // serializes the form's elements.
           success: function(data)
           {
               alert(data); // show response from the php script.
           }
         });
});  

    </script>
© www.soinside.com 2019 - 2024. All rights reserved.