0

我正在查看一些具有相同类的元素并进行 AJAX 调用,具体取决于我想要更改 img src 属性的返回值。但是使用数据属性来识别正确的对象?

 $("button.checkStatus").click(function(){
        //This Ajax checks the current on/off status of the passed X10 code
        $('.checkStatus').each(function(i, obj) {
            $x10Device = $(this).data("x10");
            //var data = "url=http://192.168.0.34:81/tenHsServer/tenHsServer.aspx?t=ab&f=DeviceStatus&d=C5" //& $x10Device ; //this is passed in the device toggle

        var data = "url=http://192.168.0.34:81/tenHsServer/tenHsServer.aspx?t=ab&f=DeviceStatus&d=" + $x10Device ; //this is passed in the device toggle

        $.ajax({                  
              url:"urlencode.php",
              data: data,
      type: "POST",
      success: function(data) { 
                  myd = $('<span />').html(data).find("#Result").text();
                  var Nmyd = myd.charAt(3);
                  if (Nmyd == '2'){$('img').attr('src','lightbulbon.png')}else{$('img').attr('src','lightbulboff.png')};    
                  },
              error: function (request, status, error) 
               {   
                alert(request.responseText);
                }
     });
     });
     });
4

0 回答 0