我正在浏览一些具有相同类并进行AJAX调用的元素,具体取决于我想要更改img src属性的返回值。但是使用data属性来识别正确的对象?
$("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);
}
});
});
});