Friday, 12 August 2016

javascript - How can I use $.ajax success data in somewhere else?


Possible Duplicate:
return from jquery ajax call
jQuery: Return data after ajax call success







        $.ajax({
url:"list.php",
dataType: "json",
success: function(resp){
for(var i=0;i $('#goods_list').append(
"

" + resp[i]["name"] + "

"
+

"
Price: NT$" + resp[i]["price"] + "
"
+
resp[i]["description"]
+
"
Add | More"
+"
"
);
}

var resp2 = resp;

}
});

$('body').append(resp2[0]["price"]);


And FireBug said:



ReferenceError: resp2 is not defined
$('body').append(resp2[0]["price"]);



How can I use $.ajax success data in somewhere else? (outside the $.ajax function)



The concept is similar to "Global Variables".

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...