Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何更改数据图标属性作为xmlHTTPRequest的结果?_Php_Jquery_Ajax_Mobile - Fatal编程技术网

Php 如何更改数据图标属性作为xmlHTTPRequest的结果?

Php 如何更改数据图标属性作为xmlHTTPRequest的结果?,php,jquery,ajax,mobile,Php,Jquery,Ajax,Mobile,我试图更改listview中给定行的数据图标。jquery attr()函数和javascript setAttribute()函数都不起作用 <script> function increment(id) { var row = "row" + id; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xml

我试图更改listview中给定行的数据图标。jquery attr()函数和javascript setAttribute()函数都不起作用

 <script>
    function increment(id) {
        var row = "row" + id;
      if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
      } else { // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
      xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
          document.getElementById("issue"+id+"Upvote").innerHTML=xmlhttp.responseText;
        $(row).attr("data-icon", "arrow-d");

        }
      }
      xmlhttp.open("GET","increment.php?q="+id,true);
      xmlhttp.send();
    }
    </script>


    //Fetching from your database table.
    $query = "SELECT * FROM $usertable";
    $result = mysql_query($query);

    if ($result) {
        while($row = mysql_fetch_array($result)) {
            $issue = $row["issueName"];
            $upvotes = $row["upvotes"];
            $id = $row["issueID"];
            echo "<li data-icon=\"arrow-u\" id=\"row".$id . "\"> <a href=\"point.php\">".$issue ."</a><a href=\"javascript:increment(".$id.");\"></a> <span id=\"issue".$id."Upvote\" class=\"ui-li-count\">" .$upvotes."</span></li>";

        }
    }

函数增量(id){
var row=“row”+id;
if(window.XMLHttpRequest){
//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}else{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.getElementById(“issue”+id+“Upvote”).innerHTML=xmlhttp.responseText;
$(行).attr(“数据图标”、“箭头-d”);
}
}
open(“GET”、“increment.php?q=“+id,true”);
xmlhttp.send();
}
//正在从数据库表中提取。
$query=“从$usertable中选择*”;
$result=mysql\u query($query);
如果($结果){
while($row=mysql\u fetch\u数组($result)){
$issue=$row[“issueName”];
$UPVOLUES=$row[“UPVOLUES”];
$id=$row[“issueID”];
echo““$upvots.””;
}
}
您将行设置为

var row = "row" + id;
但是你的选择器是

$(row)
例如,制造它

$('row1')
如果它是一个ID,它应该是

$('#'+row)
编辑选择器工作后,要更改jquery mobile中的图标,请使用
按钮标记

$('#'+row).buttonMarkup({ icon: "star" });

最好在插入dom之前更改html:

var toInsert = $( xmlhttp.responseText );
toInsert.attr("data-icon", "arrow-d");
$("#issue"+id+"Upvote").html().append( toInsert );

明白了$(row.toString()).find('.ui-icon').removeClass('ui-icon-custom').addClass('ui-icon-star');谢谢

我想你的DOM选择器有错误,你能发布你的HTML吗?没有太多其他相关的HTML。我已经更改了选择器中的错误,但它仍然不起作用。有其他想法吗?更改了该错误,但它仍然不起作用。其他可能的问题?假设您的选择器是正确的,并且您的请求是成功的,它应该可以正常工作。下面是一个示例,看起来您正在使用jQuery mobile,并试图通过更改数据属性来更改图标。那不行。。。您需要使用
按钮标记
。查看更新的答案。由于某些原因,这也不起作用。很奇怪。谢谢你的帮助,但是你还有其他想法吗?我提供了唯一相关的代码。非常感谢尝试在请求成功块中添加一个
console.log('test')
,以确保请求首先成功。假设代码块正在执行,我100%肯定我的代码可以正常工作。您可以通过输入
$('.content primary').find('a:first').buttonMarkup({icon:star})来测试它。观看第一个按钮的图标变为星形。