0

Can't seem to get the variable getID to work. I'm trying to change the html of the div. I know that the variable has the right value.

$('.cardid').change(function() {
    var getID = $(this).attr('value');

        $.ajax({
        type: "POST",
        url: "inc/change_thumbnail.php",
        data: "id="+getID,
        cache: false,
        success: function(data) {
            $("#"+getID).html(data);
            alert("success");
        },
        error: function (err) {
            alert("error"); 
        }
    });

});        
1
  • What exactly does not work? How do you know the variable has the right value, have you logged it? Commented Jan 24, 2013 at 11:22

3 Answers 3

1

Write data in $.ajax as data: {id : getID}, instead of data: "id="+getID,

Sign up to request clarification or add additional context in comments.

Comments

0

Use val to get the value of an input :

var getID = $(this).val();

As you're making a POST request, you should also use the data argument to let jQuery properly send the value :

$.ajax({
    type: "POST",
    url: "inc/change_thumbnail.php",
    data: {id:getID},
    cache: false,
    success: function(data) {
        $("#"+getID).html(data);
        alert("success");
    },
    error: function (err) {
        alert("error"); 
    }
});

3 Comments

Maybe it's a checkbox input.
Thanks. It's a select option. For some reason thought it is not passing the data through correctly? The variable does not get passed in the url
You're making a POST request. You should probably use the data argument of $.ajax.
0

You can try this:

$('[id="'+getID+'"]').html(data);

and yes you should pass it this way:

data:{id:getID}

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.