2013-10-04 65 views
0

我已經更新了ajax,但仍然沒有通過,我越來越瘋狂,請有人幫我出來。必須工作:(如何使用ajax發送數據到php文件?

function ajaxFunction(gotid){ 
    alert (gotid) 

    $.ajax({ 
     type: "POST", 
     url: "profile/php/getorder.php", 
     data: { 
     dataString: gotid 
     }, 
     success: function(msg){ 
      alert("Data Saved: " + msg); 
     } 
    }); 
    } 

和PHP

<?php 
    $ordid = $_POST["dataString"]; 
    $ordid = mysql_real_escape_string($ordid); 
    echo $ordid; 

?> 

爲什麼不能看到警報( 「數據保存:」 +味精);?幫助:(

回答

0

如果您正在使用jquery在你的頁面(就像問題的標籤中所述)你最好使用它!不需要使用XMLHttpRequest。看看這個jQuery的片段和jQuery文檔 http://api.jquery.com/jQuery.ajax/

$.ajax({ 
    url: '/path/to/file', 
    type: 'default GET (Other values: POST)', 
    dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)', 
    data: {param1: 'value1'}, 
}) 
.done(function() { 
    console.log("success"); 
}) 
.fail(function() { 
    console.log("error"); 
}) 
.always(function() { 
    console.log("complete"); 
}); 
+0

嗨,我已修改功能$就({ 類型: 「POST」, URL: 「簡檔/ PHP/getorder.php」, 數據:{sndid:gotid} }) .done(功能(味精){ 警報(「Data Saved:」+味精); }); }但仍然沒有運氣,現在我沒有第二個提醒,即使 –

+0

您應該使用GET,因爲您的php正在偵聽GET參數,而不是發佈。 –

+0

是的我知道,我也改變了服務器端,但沒有運氣 –