1
我在按鈕單擊事件中調用第三方API的函數。jQuery成功提交表單
查看下面,按鈕點擊tp.callFunction,只有在成功我想res.myNum存儲在一個隱藏的領域,並提交表單。
我感到困惑的部分是寫入或擴展的位置(.success(functionOne)),以便我可以爲表單提交一個代碼。
$('[button1]').on('click', function() {
var getdatafrom = {
param1: $('input:text').val()
};
tp.callFunction(getdatafrom)
.success(functionOne)
.error(functionFail);
return false;
});
function functionOne(res) {
alert("Sample: " + res.myNum);
};
function functionFail(res) {
alert("Error: " + res.errormessage);
};
我知道我們可以做到這一點在阿賈克斯後像下面
$.ajax({
data: { 'field1' : email },
type: 'GET',
dataType: 'json',
url: 'url.php',
beforeSend : function(){ },
success: function(answer){
if(answer.error === false){
$('#greatForm').attr('validated',true);
$('#greatForm').submit();
}
if(answer.error === true){
//display the errors
}
}
});
如果你知道如何在匿名函數中做到這一點,它會不會在命名函數中完全相同? – adeneo