[jQuery] function to call ajax
Hi,
I've been work working jQuery for more than 4 month, and really love
it. There are still a lot thing I need to learn, here is one:
I like to create a function, Get_MyData. test_ajax() alway return
"undefine". what's wrong in my code, what's the proper way to do
this?
Thank you very much for your time.
Wes
code:
//
function Get_MyData (para1)
{
var parameters = "AjaxServer.aspx?para1=" + para1;
$.getJSON(parameters, function(data) {
// error handle
if (!onError(data)) return "";
//
var retList = [];
$.each(data.data, function(i, xy) {
retList .push("<option value='");
retList .push(xy.id);
retList .push("'>");
retList .push(xy.name);
retList .push("</option>")
});
return str = retList .join("");
});
}
// test function
function test_ajax()
{
var str = Get_MyData(1);
alert (str);
}