从jquery ajax发送数据并从php接收数据

时间:2014-12-05 16:27:58

标签: php jquery html ajax

我遇到了Jquery Ajax和PHP的问题。我正在尝试将数据从我的脚本发送到php文件,该文件应该进一步处理数据。但是我没有收到来自php的任何回复...

html:

<form id="form-comment">
   <textarea id="popup-text" name="comment-text" placeholder="Skriv din kommentar her"></textarea>
   <input id="popup-close" type="button" value="Annuller"/>
   <input id="popup-ok" type="submit" value="OK"/>
</form>

Jquery:

$('#form-comment').submit(function(event){
var comment = $('#popup-text').val()
var c_pdf = $('#current-pdf').attr('data')
var pdf_array = c_pdf.split("/")
var post_data = pdf_array[1].trim() + " " + pdf_array[2].slice(0,-4)

$.ajax({
    url: 'php/handler-comment.php',
    type: "post",
    data: post_data,
    succes: function(response){
        console.log("PHP responded with: " + response)
    }
}).fail(function(){
    console.log("Fail")
})  

})

PHP

echo "Test";

失败功能未触发,但成功功能从不打印任何内容。我可以在ajax之前和之后使用console.log数据。你能帮我找到问题吗?感谢。

1 个答案:

答案 0 :(得分:2)

success字出现错误:

$.ajax({
    url: 'php/handler-comment.php',
    type: "post",
    data: post_data,
    success: function(response){
        console.log("PHP responded with: " + response)
    }
}).fail(function(){
    console.log("Fail")
})  
相关问题