0

I'm trying to retrieve multiple $_GET variables within PHP. Javascript is sending the URL and it seems to have an issue with the '&' between variables.

One variable works:

 //JAVASCRIPT
 var price = "http://<site>/realtime/bittrex-realtime.php?symbol=LTC";

 //THE PHP END
 $coinSymbol = $_GET['symbol'];
 echo $coinSymbol

 OUTPUT: LTC

With two variables:

 //JAVASCRIPT
 var price = "http://<site>/realtime/bittrex-realtime.php?type=price&symbol=LTC";

 //THE PHP END
 $coinSymbol = $_GET['symbol'];
 $type = $_GET['type'];
 echo $coinSymbol
 echo $type

 OUTPUT: price

It just seems to ignore everything after the '&'. I know that the PHP end works fine because if I manually type the address into the browser, it prints both variables.

 http://<site>/realtime/bittrex-realtime.php?type=price&symbol=LTC

 OUTPUT ON THE PAGE
 priceLTC

Any ideas? It's driving me nuts - Thanks

UPDATE - JAVASCRIPT CODE

jQuery(document).ready(function() {
refresh();

jQuery('#bittrex-price').load(price);

});

function refresh() {

   setTimeout( function() {
        //document.write(mintpalUrl);
        jQuery('#bittrex-price').fadeOut('slow').load(price).fadeIn('slow');

        refresh();

   }, 30000);
}
17
  • Can you show us the javascript code that is submitting to your PHP script? Commented Sep 22, 2014 at 2:29
  • Where's the JS code that uses that price variable? Commented Sep 22, 2014 at 2:30
  • 2
    Tip: The proper tools for debugging in this situation are var_dump and print_r, e.g. var_dump($_GET). Commented Sep 22, 2014 at 2:30
  • Could you try escaping your ampersand. &amp; instead of & Commented Sep 22, 2014 at 2:33
  • 1
    Trust me lol I know. I'm confused how it's fine in the query_String but not in $_GET. Commented Sep 22, 2014 at 2:45

1 Answer 1

1

Separate the url and the data that you will be sending

var price = "http://<site>/realtime/bittrex-realtime.php";

function refresh() {

   var params = {type:'price', symbol: 'LTC'};

   setTimeout( function() {
        //document.write(mintpalUrl);
        jQuery('#bittrex-price').fadeOut('slow').load(price, params).fadeIn('slow');

        refresh();

   }, 30000);
}

And in your PHP use $_POST or you can do it like this

$coinSymbol = isset($_POST['symbol']) ? $_POST['symbol'] : $_GET['symbol'];

Refer to here for more information jquery .load()

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

8 Comments

I can't get this to work :( - It's worth noting that the Javascript I've added above is fixed in the header & I'm creating the variables in the body. This is my first time working with Javascript so I'm not sure if that makes any difference? Thanks @andrex
@Ryan I'm confuse how did you manage to construct the url with the parameters in the first place?
I need to get several different bits of information from http://<site>/realtime/bittrex-realtime.php - The only way I could think to do it was to use $_GET variables to have the page display a different bit of information each time it was called. The URL is just manually typed in, I'm not constructing it with any concatenation...yet @andrex
Now why can't you get it to work? You are manually typing the url right. For now instead using the url with the parameters in the load function, separate it like how I wrote it. Even if it's separated it will still be passed to the php side, Also read more about the load function in the link. There are examples there too.
I just can't see why the original method works with one variable but not 2 :/ - I've had a quick look at the link you've supplied, it looks beyond my knowledge at first glance, I'm not the most savvy coder. I'll spend some time researching the .load function tomorrow and see if I can find a simple explanation to get me from A > B- I've been trying to get this whole Javascript bit trying to run for about 15 hours straight - I'm done with it for today, I'm out. Thanks for your help, I'll do some research tomorrow
|

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.