2013-11-21 28 views
0

我試圖將數據發佈到處理php頁面的背景中。在JavaScript運行之後,我運行了一些不應該成爲問題的PHP。使用Javascript將數據發佈到處理頁面

這裏是我的代碼:

<script type="text/javascript" src="jquery-1.8.2.min.js"></script> 

<script> 
$(function(){ 
     $.ajax({ 
      url: 'https://processingsiteurl.com/register2.php', 
      type: 'POST', // GET or POST 
      data: 'f_refer_by="129"&sinup_id="2"&sinup_z_First_Name_="Rossontf1"&sinup_z_Last_Name_="Ras4z123a"&sinup_z_Email_="[email protected]"&sinup_z_Choose_Password_="abc123"&sinup_z_Confirm_Password_="abc123"&sinup_z_Fundraiser_Display_Name="Test123"&sinup_z_Fundraiser_Dates="Test123"&sinup_z_Members_in_Organization="73"&sinup_z_Email_Format_="1"&sinup_z_Name_of_Campaign="Test123".val()', // will be in $_POST on PHP side 
      success: function(data) { // data is the response from your php script 
       // This function is called if your AJAX query was successful 
       alert("Response is: " + data); 
      }, 
      error: function(data) { 
       // This callback is called if your AJAX query has failed 
       alert("Error!" + data); 
      } 
     }); 
    }); 
</script> 

的問題是,我得到一個「的翻譯:」錯誤。然後腳本死亡。

+0

'警報(參數[2])'和檢查控制檯錯誤。 –

+0

出現'[object Object]'在錯誤回調的警報中?嘗試'console.log(data);' – Izkata

回答

0

你可以試試這個:

var xmlhttp; 
if (window.XMLHttpRequest) 
{// code for IE7+, Firefox, Chrome, Opera, Safari 
    xmlhttp=new XMLHttpRequest(); 
} 
else 
{// code for IE6, IE5 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 
xmlhttp.open("POST","https://processingsiteurl.com/register2.php",false); 
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
xmlhttp.send("f_refer_by=129&sinup_id=2.......other parameters....."); 
+0

嗨Mykola ....我嘗試了你的建議,但它不起作用...? –

+0

@ user3018854嘗試使用幾個簡單的參數。也許問題是在正確的編碼或雙引號... –

1

簡化你的ajax數據並把它放在一個對象中,而不是一個字符串;你對自己過於苛刻。例如:

// Everything before data goes here 
     data: { 
      "f_refer_by": "129", 
      "sinup_id": "2", 
      "sinup_z_First_Name_": "Rossontf1", 
      "sinup_z_Last_Name_": "Ras4z123a", 
      "sinup_z_Email_": "[email protected]", 
      "sinup_z_Choose_Password_": "abc123", 
      "sinup_z_Confirm_Password_": "abc123", 
      "sinup_z_Fundraiser_Display_Name": "Test123", 
      "sinup_z_Fundraiser_Dates": "Test123", 
      "sinup_z_Members_in_Organization": "73", 
      "sinup_z_Email_Format_": "1", 
      "sinup_z_Name_of_Campaign": '"Test123".val()' // will be in $_POST on PHP side 
     }, 
// Everything after data goes here 

此外,有一個包含"Test123".val()的值。我懷疑這是你想要的。這聽起來像你可能意味着像$('#Test123').val(),但我不知道。

+0

嗨,謝謝你的回答...我用你的建議,但我仍然得到相同的錯誤... –

+0

你的PHP腳本返回的響應是什麼?如果您的腳本正在返回,例如JSON數據,那麼當您提示「+ data」時,jQuery可能會翻轉出來。 –

相關問題