2013-03-04 28 views
1

最後一個線程充滿了錯誤,粘貼時發生錯誤。用PhoneGap發送一個PHP表格

首先,我一直在玩PhoneGap,我最終試圖做的是建立一個聯繫表單的應用程序,將結果通過電子郵件發送到我選擇的電子郵件(以及一張圖片攝像頭應用程序)(或結果發佈到服務器甚至)

我發現this,我一直在試圖複製它,以得到我的表單將如何工作,但是,我似乎無法讓它運行。

繼承人一步一步的我到目前爲止。

的index.html - >只鏈接callsheet.html

callsheet.html

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Send in CallSheet</title> 

    <script type="text/javascript" charset="utf-8" src="js/cordova-2.5.0.js"></script> 
    <script type = "text/javascript" charset="utf-8" src="js/index.js"></script> 
    <script type="text/javascript" charset="utf-8"> 


    // Wait for Cordova to connect with the device 
    // 
    document.addEventListener("deviceready",onDeviceReady,false); 
</script> 

    </head> 
    <body> 
<form action="http://contest.phoenixamd.com/ANDROIDTEST/callsheet.php" method="post"> 
      <div class="form-element"> 

     <label for="msg">Message</label> 
     <textarea id="msg" name="msg" placeholder="required" rows="5" required ></textarea> 
     </div> 
     <input type="button" value="submit contact"/> 
     </form> 
    </body> 
</html> 

callsheet.php(我的遠程服務器上)

<?php 
    require_once("class.phpmailer.php"); 


    $MessageText=$_POST["msg"]; 


    $mailer = new PHPMailer(); 
    $mailer->isSMTP(); 
    $mailer->CharSet='utf-8'; 
    $mailer->AddAddress("[email protected]", "Gabe"); 
    $mailer->Subject="Mobile App Message"; 
    $mailer->From = '[email protected]'; 
    $mailer->Body = $MessageText; 


    //VALIDATION 
    if(
    empty($MessageText) 
    ) { 
     echo "Error"; 
    } else { 
     $mailer->Send(); 
     echo "Success"; 
    } 

?> 

index.js(其中即時保持我的jquery)

// When the document has loaded... 
$(document).ready(function() { 
    // Bind this action as a function to be executed when the button is clicked... 
    $('input[type="button"][value="submit"]').click(function() { 
    $.post('http://contest.phoenixamd.com/ANDROIDTEST/callsheet.php', { 


     MessageText: $('#msg').val() 

     // HTML function 

     }, function (html) { 
      // Place the HTML in a astring 
      var response=html; 

      // PHP was done and email sent 
      if (response=="Success") { 
      alert("Message sent!"); 
      } else { 

      // Error postback 
      alert("Please fill all fields!"); 
      return false; 
      } 
    }); 
    }); 
}); 

我試過以下步驟herehere,但似乎無法弄清楚什麼是錯的......當我點擊提交時,絕對沒有任何反應。

我的PHP文件有效,如果我通過this提交,它會迴應成功併發送電子郵件。

如果我改變我的PHP提交而不是按鈕,它的工作原理,但這只是使用HTML和PHP,而不是應用程序本身的實際JS。

+0

是否有什麼你JS錯誤控制檯? – BenOfTheNorth 2013-03-04 01:26:27

+0

超時錯誤:( – 2013-03-04 01:36:11

+0

哦,它的說話無法打開文件閱讀 – 2013-03-04 01:37:54

回答

1

首先,如果您的域名未在​​3210列入白名單,我認爲該請求不會被允許。

我無法從你的文本中知道你的示例在哪個設備上失敗 - 如果我是在Android上,我只是grep logcat輸出中的任何錯誤,默認情況下CordovaWebView會發送這些錯誤。

+0

已添加將域名添加到白名單中,現在只要我啓動應用程序就直接跳到錯誤 – 2013-03-04 01:32:43

+0

<! - - > 如果我取消註釋,立即出錯。 – 2013-03-04 01:43:23

+0

我期待着你添加s.th.如。從未見過你描述的contant-tag。此外:錯誤的類型是什麼,它說什麼?您正在測試的平臺/設備是什麼? – Philzen 2013-03-04 04:26:39

0

在HTML文件中,你的輸入類型=「按鈕」應該已經輸入類型=「提交」,嘗試了這一點幾次我有這個問題我自己....