0

I am having an issue with Jquery Ajax and PHP. I am trying to send data from my script to a php file which should handle the data further. But I am not getting any response from the php...

The 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>

The 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";

The fail function is not triggering, but the succes function never prints anything. I can console.log data before and after the ajax. Can you help me find the problem? Thanks.

4
  • And I am aware of that I am not using the post_data for anything in the php file, but that is not the issue here. I would like the response "Test" to be printed in my jquery Commented Dec 5, 2014 at 16:29
  • I think ` succes: ` should be ` success: ` Commented Dec 5, 2014 at 16:31
  • You are not preventing your form from posting/refreshing. try adding a event.preventDefault(); inside $('#form-comment').submit(function(event){ ... }); Commented Dec 5, 2014 at 16:32
  • Ah, that is something I was looking at as well. Thank you! Commented Dec 5, 2014 at 17:08

1 Answer 1

2

You have an error with the success word :

$.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")
})  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.