2013-07-18 100 views
0

我有一些类='chkspec'的复选框,我会将单击的复选框的ID值传递给xxx.php文件。我的问题是:将复选框ID传递给带有AJAX的php文件

1)我不知道怎么打发我试着用 “specificitem = this.id”的ID,但我不知道这是正确的方式

2)我得到这个错误:未定义的变量:specificitem。如果我做specificitem =“hello”,这也会发生;

代码如下。

如果($( 'chkspec。')是( “:勾选”)){

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

        data: {specificitem : this.id } 

       } 


      } 
     }; 

感谢您的答复。

回答

0

我不会真正知道纯粹的JS我更多的JQuery人。 我会做这样的:

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

我想是因为数据是从哪儿冒出来你得到这个错误。