2012-02-12 15 views
0

在qm150_submit $ .post中的ajax調用之後的回調函數中。我想調用第二個名爲'send_email'的函數(它也有一個名爲「success_callback」回調Uncaught TypeError:object [object DOMWindow]的屬性不是函數

的SEND_EMAIL叫,但我得到這個錯誤:

Uncaught TypeError: Property 'send_email' of object [object DOMWindow] is not a function 

這是一個引用錯誤,我需要做些什麼來設定什麼都.this也許是??

功能從colorbox iframe調用。我不確定這與它有什麼關係?

這裏是代碼:

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'); 
     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) }; 

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; 
} 
+0

您可能希望在其他地方發佈.js文件的其餘部分,因爲您可能會用腳本中其他位置的某個函數覆蓋send_email函數。另外,你還沒有包含上一個問題(適當的'send_email'調用)的變化,這可能會誤導人們 - 事實證明它的確如此...... – JimmiTh 2012-02-12 09:28:35

+0

@ TheKaneda你的改變現在已經包含在內了,我的錯誤。感謝您的幫助 – johowie 2012-02-12 09:51:49

+0

主窗口和colorbox iframe都包含相同的腳本。 – johowie 2012-02-12 09:58:13

回答

0

只需調用該函數。

send_email(fromName,fromEmail,toEmail,subject,message,success_callback); 
+0

對此深表歉意,正如TheKaneda @TheKaneda所承認的那樣,我錯誤地發佈了在上一個問題中已被糾正的代碼。請參閱現在應用的編輯。感謝大家的幫助。 – johowie 2012-02-12 09:50:46

相關問題