Reputation: 3
$(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
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
Reputation: 7802
do you by chance have 2 spans on top of each other?
your function works fine: see this fiddle:
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