我試着去使用這個jQuery腳本,這是混淆了我:解釋jQuery的AJAX成功方法
function CallService()
{
$.ajax({
type : varType, //GET or POST or PUT or DELETE verb
url : varUrl, // Location of the service
data : varData, //Data sent to server
contentType : varContentType, // content type sent to server
dataType : varDataType, //Expected data format from server
processdata : varProcessData, //True or False
success : function(msg) {//On Successfull service call
ServiceSucceeded(msg);
},
error: ServiceFailed// When Service call fails
});
}
位IM困惑是的研製成功對象。 jQuery的文件說:
success(data, textStatus, jqXHR)Function, Array
A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the dataType parameter; a string describing the status; and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object. As of jQuery 1.5, the success setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event.
但這種方法的簽名看起來一點也不像。
success : function(msg) {//On Successfull service call
ServiceSucceeded(msg);
}
對象,我們似乎傳遞
問題:
1)什麼function(msg){ServiceSucceeded(msg)}
是什麼意思?
2)在這種情況下'msg'是什麼?
3)我是怎麼知道如何構建成功的方法sugnature?
嗨TJ,你的答案真的幫助我非常感謝,我可以看到現在發生了什麼會簡單一點。 – Exitos 2011-05-18 15:35:19
只是閱讀你的更新,這真的很有幫助,現在解釋很多。我從來沒有意識到JavaScript可能會「超載」?以這種方式... – Exitos 2011-05-18 15:42:06
@ Pete2k:不用擔心,很高興幫助!是的,JavaScript函數是非常自由的形式,這使得它們非常強大,具有所有的優點和缺點。 ;-) – 2011-05-18 15:48:29