我还是PHP的新手,并创建了一个带有按钮的表单,该按钮在单击时执行以下操作:
$(".changePassBtn").on('click', function() {
console.log("WORKS!!");
$.ajax({
url: "../php/passwordchange.php", // Url to which the request is send
type: "POST", // Type of request to be send, called as method
data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
contentType: false, // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false, // To send DOMDocument or non processed data file it is set to false
success: function(data) // A function to be called if request succeeds
{
}});
});
我知道这是因为console.log正在执行。这会调用../php/passwordchange.php(Chrome没有显示任何错误,找到它),其中包含以下内容:
<?php
echo "Hello world";
?>
但没有任何回应。我可能在这里错过了一些简单的东西;如何让PHP运行?
答案 0 :(得分:0)
在此功能中:
success: function(data) // A function to be called if request succeeds
{
}});
记录数据,像这样
success: function(data) // A function to be called if request succeeds
{
console.log(data);
}});
答案 1 :(得分:0)
您必须在请求完成时调用函数,并且在@hossein barzegari的答案中,它只会将数据记录到控制台中。
success: function(response) { $('.object-to-print').text(response); }
当php目标文件回显时,这将进入.object-to-print。