0

I am trying to update my database when the user clicks a certain link (links have different values, so when user clicks one link number goes up by 1, another by 2, and so on).

I need to submit a form to another page containing the data from #form with a variable behind it, but this function doesn't seem to be working.

JavaScript

function update_number(x) {

    $.ajax({
        type: "POST",
        url: "update_likes.php",
        data: $("#Form"+x).serialize(),
        dataType: "json",

        return false;
        };

HTML

<input type='image' src='...' onclick'update_number(2);' />

Any help appreciated.

1
  • what have you tried so far? this looks like a copy / paste code and that you do not know javascript at all. this place is not for teaching you how to properly code. its for giving answers to true questions. Commented Dec 1, 2012 at 23:43

1 Answer 1

1

It seems that your JavaScript is not closed correctly.

Try changing your JavaScript with this:

function update_number(x) {
    $.ajax({
        type: "POST",
        url: "update_likes.php",
        data: $("#Form"+x).serialize(),
        dataType: "json",
        success: function(json) {
            alert( json );
            return false;
        }
    });
 }
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.