user7031 user7031 - 1 year ago 80
Ajax Question

Jquery ajax post doesn't send data to server end(Using PHP)


<a id="1">Add to notebook</a>
<a id="2">Add to notebook</a>
<a id="3">Add to notebook</a>
<a id="4">Add to notebook</a>
<a id="40">Add to notebook</a>


//callback handler for post submit
var vocab_id = $(this).attr("id");
var formURL = 'http://localhost/test/test.php';
url : formURL,
type: "POST",
data : vocab_id,
dataType : "text",
e.preventDefault(); //STOP default action
//e.unbind(); //unbind. to stop multiple form submit.

I have a list of hyperlinks, it will send the currently clicked value of id to the server end by clicking the respective link.

But the problem is

  1. Back-end doesn't receive any post data at all.

  2. People said that I should uncomment the e.unbind() to stop multiple submit, but I got error after that line was uncommented. Error message is like this.

Uncaught TypeError: undefined is not a function 2:479(anonymous function) 2:479n.event.dispatch jquery-1.11.0.js:3r.handle

Answer Source

The data part in jQuery.ajax() should be like either

data :{ name : vocab_id } 


data : "name="+vocab_id

Syntax for unbind() is not correct use the following


it will unbind the object from current event handler