在使用JQUERY AJAX中,有個菜鳥問題請教,
忘各位高手,前輩不吝賜教!
感謝為先!
使用AJAX POST到後來後
返回JSON數據,而我每次需要使用這個JSON數據都需要定義全局變量來使用,不能使用直接返回結果,是寫法問題,還是有其他方
法?
代碼:
[code="java"]
var dataJson;
function bind()
{
$.ajax({
type: "post",
dataType: "json",
url: "ashx/Main.ashx",
data: "&Condition="+p_Condition+"&MothodName=GetApplyData",
complete :function(){},
error: function(){},
success: function(result)
{
dataJson = result;
}
});
}
function UseData()
{
[b] 目前是定義全局變量 dataJson 來接受返回值
先執行 方法 bind();
再使用 dataJson [/b]
我想變成
var dataJson = bind();
缺不行
}
[/code]