0

I have some checkboxes with class='chkspec' and I would to pass the ID value of the clicked checkbox to a xxx.php file. My problems are:

1) I don't know how to pass the ID I tried with "specificitem=this.id" but I'm not sure it is the right way

2) I get this error: Undefined variable: specificitem. This occur also if I do specificitem="hello";

code is below.

if ($('.chkspec').is(":checked")) {

        xmlHttp.open('POST', "xxx.php", true);    
        xmlHttp.onreadystatechange = function() 
        {
            if(xmlHttp.readyState == 4) 
            { 
                if (xmlHttp.status == 200) 
                {

                    data: {specificitem : this.id } 

                }


            }
        };

Thank you for replies.

4

1 回答 1

0

我真的不知道纯 JS 我更喜欢 JQuery 人。我会这样做:

if ($('.chkspec').is(":checked")) {
    var data;
    $.ajax({
        url:"xxx.php",
        data:$('.chkspec').attr('id'),
        method:'post', 
        success:function(result){
           ;//
        }
    });
}

我认为您会收到此错误,因为数据无处不在。

于 2013-07-18T16:55:01.573 回答