2

I'm using AJAX to update a page every 5000 milliseconds. It works great but I have ran into one issue. When I try and get data that is in the URL using $_GET or $_POST it does not work. It instead returns a value of a 1. Here is some example code.

In main.php I have this:

$(document).ready(function worker() {
    $.ajax({
        url: 'Request.php', 
        type: 'POST',
        success: function(data) {
            $('#Live_data').html(data);
        },
        complete: function() {      
            setTimeout(worker, 5000);
        }
    });
})();

and when this is called it fires off the request.php. In request.php I have some code to grab what was added in the URL by a previous page but it dose not work. It goes something like this:

$value = $_get['test'];

This is supposed to return the value in the URL parameter test but it does not work.

Thanks!

5
  • you need parse the result or specify the dataType example dataType:'text' Commented May 17, 2016 at 8:32
  • You're not sending any values in your AJAX request; you need to add a data property with the required values to send in the request. Commented May 17, 2016 at 8:33
  • your not sending any data here ? Commented May 17, 2016 at 8:37
  • $_GET , not $_get in $_get['test']; Commented May 17, 2016 at 8:39
  • First thing: You are using POST in your ajax request and GET in your Request.php. Second is that you are using Request.php and request.php. One is capital, the other isnt. Third thing i notice is that you are using $_get instead of $_GET. This variable is case sensitive. Commented May 17, 2016 at 8:41

3 Answers 3

3

You forgot to send data with the ajax query,

In this code, you can add GET data by append a query string to url value, or send POST data by setting data property of the request,

    $.ajax({
        url: 'Request.php?query=string&is=here', 
        type: 'POST',
        data: {to: 'post', goes: 'here'},
        success: function(data) {
            $('#Live_data').html(data);
        },
        complete: function() {      
            setTimeout(worker, 5000);
        }
    });

see also https://api.jquery.com/jquery.post/#jQuery-post-settings

Sign up to request clarification or add additional context in comments.

1 Comment

I sure did! Thank you! Request.php?query=<?php echo $string?>
1

I've commented it as well but I'll post it as answer:

  1. Change POST to GET in your jQuery AJAX request.
  2. Use request.php instead of Request.php or the other way around.
  3. Use $_GET instead of $_get. This variable is case sensitive.

Comments

0

Your not sending any data here. You can send the required data in Url or in Data Field.

url: 'Request.php?test=xyz', 

or

data: data,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.