Sinagaman Eidelbert
Sinagaman Eidelbert

Reputation: 27

AJAX Post two id

can I send two id in ajax post? can i make like this? but this script not work..

<a href='#' class='plyshr' id1="<?php echo $tracks['track_id']; ?>" id2="<?php echo $row[2]; ?>">
    <?php echo $row[2]; ?>
</a>

and in AJAX

some more details

$(document).ready(function(){
    $(".plyshr").click(function () {
        var id = $(this).attr("id");
        var dataString = 'id1=' + id1;
        var dataString = 'id2=' + id2;
        var parent = $(this);

        $.ajax({
            type: "POST",
            url: "playlist.php",
            data: dataString,
            cache: false,

            success: function (html) {
                parent.html(html);
            }
        });

        return false;

    });
});

Upvotes: 0

Views: 269

Answers (3)

Rohan Kumar
Rohan Kumar

Reputation: 40639

Why are you using custom attributes, you can use data attribute, like

<a href='#' class='plyshr' data-id1="<?php echo $tracks['track_id']; ?>" 
      data-id2="<?php echo $row[2]; ?>">
    <?php echo $row[2]; ?>
</a>

SCRIPT

$(".plyshr").click(function () {
    var self=this;
    var parent = $(this);
    $.ajax({
        type: "POST",
        url: "playlist.php",
        // use jquery data function here
        data:{id1: $(self).data('id1'),id2:$(self).data('id2')},
        cache: false,

        success: function (html) {
            parent.html(html);
        }
    });
    return false;
});

Upvotes: 0

maximkou
maximkou

Reputation: 5332

var id1 = $(this).attr('id1'),
   id2 = $(this).attr('id2'),
   dataString = 'id1='+ id1 ;
dataString += '&id2='+ id2 ;

Upvotes: 1

Subir Kumar Sao
Subir Kumar Sao

Reputation: 8411

Assuming rest of the code is working.

var id1 = $(this).attr("id1"); // Get the first id.
var id2 = $(this).attr("id2");  // Get the second id.
var dataString = 'id1='+ id1 ;
dataString += '&id2='+ id2 ;  // Set both in string with & separtor

Upvotes: 1

Related Questions