markusmark
markusmark

Reputation: 3

json data repeat itself 2 times

$(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 />");
                   });
               }
           });
    }

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?

Upvotes: 0

Views: 256

Answers (2)

Greg
Greg

Reputation: 23473

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.

Upvotes: 1

Patricia
Patricia

Reputation: 7802

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.

Upvotes: 1

Related Questions