开发者

json data repeat itself 2 times

开发者 https://www.devze.com 2023-03-10 00:17 出处:网络
$(document).ready(function() { $(\"button\").click(getir); }); function getir() { $.ajax({ dataType: \"json\",
$(document).ready(function() {
       $("button").click(getir);
   });

    function getir() {
         $.ajax({
               dataType: "json",
               url:"get.php",
               success: function(datacall) {
                   $.each(datacall,function(index,vals) {
                       $("span").append(index + " : " + vals + "<br />");
                   });
               }
    开发者_如何学JAVA       });
    }

the json data is {"sez":"soze","koz":"koze"} but i get a result like:

sez : soze
koz : koze
sez : soze
koz : koze

i couldnt get why its repeated 2 times?


do you by chance have 2 spans on top of each other?

your function works fine: see this fiddle:

http://jsfiddle.net/G2ntr/

so, either your data doesn't look like what you say it looks like, or you've got more then one span in your html.


If there is more than one span on the page, each span will have the text appended to it. Restrict jQuery to operating on only one span by specifying a more specific selector, such as an id or class.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号