1

HTML

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

JavaScript

<script>
$(document).ready(function(){
    //callback handler for post submit
    $("a").click(function(e)
    {
        var vocab_id = $(this).attr("id");
        var formURL = 'http://localhost/test/test.php';
        $.ajax(
        {
            url : formURL,
            type: "POST",
            data : vocab_id,
            dataType : "text",
        });
        e.preventDefault(); //STOP default action
        //e.unbind(); //unbind. to stop multiple form submit.
    });
});
</script>

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

8
  • 2
    data part shoulbe either data :{ name : vocab_id } or data : "name="+vocab_id Commented Oct 18, 2014 at 16:43
  • What are you seeing in the php error log or in FireBug, or whatever your browser uses to display status? Commented Oct 18, 2014 at 16:44
  • @PranavCBalan thank you,that solved my first problem,but why the e.unbind went wrong Commented Oct 18, 2014 at 16:50
  • @Len_D Uncaught TypeError: undefined is not a function,this error message shown in my chrome console panel Commented Oct 18, 2014 at 16:50
  • 1
    use $( this ).unbind( e ); , it will unbind the object from current event handler Commented Oct 18, 2014 at 16:52

1 Answer 1

1

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

data :{ name : vocab_id } 

or

data : "name="+vocab_id

Syntax for unbind() is not correct use the following

$(this).unbind(e);

it will unbind the object from current event handler

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.