2014-10-01 60 views
0

我想追加textboxValue到URL - ?test.php的附加JavaScript變量jQuery的AJAX網址

網址應爲test.php的變量= 「textboxValue」

var textboxValue = document.getElementById("textbox").value; 

window.onload = function() { 

window.addEventListener('shake', shakeEventDidOccur, false); 

//define a custom method to fire when shake occurs. 
function shakeEventDidOccur() { 
    $.ajax({url:"test.php?value=var textboxValue"}); 

} 

我怎樣做這個?

+0

'$阿賈克斯(網址:{url: 「test.php的價值=?」 + textboxValue});' - 字符串連接 - 你也可能要移動'VAR textboxValue =文件.getElementById(「textbox」)。value;'到'shakeEventDidOccur',這樣我們將從輸入 – 2014-10-01 13:25:20

+0

'$ .ajax({url:「test.php?value =」+ textboxvalue});' – Hackerman 2014-10-01 13:25:26

+0

可能的重複:http://stackoverflow.com/questions/3066070/using-jquery-to-make-a-post-how-to-properly-supply-data-parameter – xDaevax 2014-10-01 13:52:06

回答

1
$.ajax({url:"test.php?value="+textboxValue}); 

OR

$.ajax(
    {url:"test.php"}, 
    {data:{value:textboxValue}} 

); 
+0

發送兩個設置對象是否有效? – Popnoodles 2014-10-01 13:48:36

+0

當由php – 2014-10-01 13:48:50

+0

讀取時,值爲空。$ .ajax({url:「test.php?value =」+ textboxValue});爲我工作 – 2014-10-01 13:54:09

0

您可以簡單地連接。

url:"test.php?value="+$('#id').value()} 
3

敢肯定你可以使用data財產爲這種事情......

$.ajax({ 
    url: "test.php", 
    data: { value: textboxValue } 
}); 
0

如果要使用$阿賈克斯您需要包含jQuery源代碼,然後您也可以使用jQuery函數來執行此操作。

試試這個:

//Into your html "head" tag you need to have this: 
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script> 

//And then in your code you could have something like this: 
$(document).ready(function() { 
    window.addEventListener('shake', shakeEventDidOccur, false); //You have now the task to find what jQuery function or method could be replacing this to make your code integrated completly 

    //define a custom method to fire when shake occurs. 
    function shakeEventDidOccur() { 
     var textboxValue = $('#textbox').val(); //Where textbox is the "id" attr of your textbox 
     $.ajax({url:"test.php" 
       type: 'GET', //can be POST too 
       url: '/wp-admin/admin-ajax.php', 
       data: { 'value': textboxValue}, 
       success: function (request_data) { 
        //some code to execute after the call as a callback 
       } 
     }); 
    } 
});