0

I want to append textboxValue to the URL - test.php

The URL should be test.php?variable="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"});

}

How do I do this?

Hackerman
  • 12,139
  • 2
  • 34
  • 45
Cody Raspien
  • 1,753
  • 5
  • 26
  • 51
  • `$.ajax({url:"test.php?value="+textboxValue});` - string concatenation - also you might want to move `var textboxValue = document.getElementById("textbox").value;` to `shakeEventDidOccur` so that we will get the updated value from the input – Arun P Johny Oct 01 '14 at 13:25
  • `$.ajax({url:"test.php?value="+textboxvalue});` – Hackerman Oct 01 '14 at 13:25
  • possible duplicate of: http://stackoverflow.com/questions/3066070/using-jquery-to-make-a-post-how-to-properly-supply-data-parameter – xDaevax Oct 01 '14 at 13:52
  • $.ajax({url:"test.php?value="+textboxValue}); worked for me. – Cody Raspien Oct 01 '14 at 13:53

4 Answers4

3

Pretty sure you can make use of the data property for this kind of thing...

$.ajax({
    url: "test.php",
    data: { value: textboxValue }
});
musefan
  • 47,875
  • 21
  • 135
  • 185
1
$.ajax({url:"test.php?value="+textboxValue});

OR

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

);
Igor
  • 15,833
  • 1
  • 27
  • 32
Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73
0

You can simply concatenate.

url:"test.php?value="+$('#id').value()}
PSR
  • 39,804
  • 41
  • 111
  • 151
0

If you will use $.ajax you need to have included the jQuery source, and then you can also use the jQuery functions to do that.

Try this:

//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
                }
        });
    }
});
Rodrigo Techera
  • 251
  • 1
  • 9