在qm150_submit $ .post中的ajax調用之後的回調中。 我想調用第二個名爲'send_email'的函數(它也有一個名爲'success_callback'的回調函數「意外的令牌錯誤調用回調中的函數
我正在這裏一個錯誤
function() {send_email(fromName,fromEmail,toEmail,subject,message,success_callback) };
錯誤:未捕獲的SyntaxError:意外的標記)
這裏是代碼:
function qm150_submit($title, $name, $email, $description, $send_email) {
$.post('<?PHP print API_SUBMIT; ?>', { "title": $title, "name": $name, "email": $email, "description": $description },
function (data) { // callback function after API_SUBMIT
// Send email with a link to their collection
if ($send_email) {
// parameters for the send_email() ajax function
var subject = "subject";
var collection_id = data.collection_id; // data is json returned from the ajax above
var toEmail = $email
var message = "<?PHP print SHARE_COLLECTION;?>"+collection_id;
var fromEmail = "<?PHP print EMAIL_FROM_EMAIL; ?>";
var fromName = "<?PHP print EMAIL_FROM_NAME; ?>";
var success_callback = function (results) {
alert('send_email has returned with: '+results);
};
alert('I am now calling the send_email');
function() {send_email(fromName,fromEmail,toEmail,subject,message,success_callback) };
}
});
// missing a curly bracket ? no! note double indentation of the anonymous function (data) is a continuation of first statement
}
編輯:和爲SEND_EMAIL()
function send_email(fromName,fromEmail,toEmail,subject,message,success_callback) {
alert('send_email called');
$.ajax({
type: 'post',
url: '<?PHP print API_SHARE_EMAIL;?>',
data: 'fromName=' + fromName + '&fromEmail=' + fromEmail + '&toEmail=' + toEmail + '&subject=' + subject + '&message=' + message,
dataType:'json',
success: success_callback
});
alert('send_email finished');
return true;
}
這是有道理的,現在我有一個引用問題,從該secondcallback獲取此錯誤'未捕獲的TypeError:對象[對象DOMWindow]的屬性'send_email'不是函數'我會開始一個新的問題,如果除非你或某人有一些快速的建議 – johowie 2012-02-12 08:49:26
嗯,看起來你的函數實際上被稱爲'$ send_email',而不是'send_email'?如果沒有看到更多的代碼,肯定不會知道。 – JimmiTh 2012-02-12 09:00:02
$ send_email是一個真或假的變量,如果$ send_email爲真,send_email()是一個應該被調用的函數。我將編輯我的帖子以包含send_email()函數。 – johowie 2012-02-12 09:09:19