0

I am writing an app using JQuery Mobile and PHP.

The problem: When I try to pass values from one JQuery mobile page (e.g. from #page1 to #page2 using Ajax and PHP) $_GET does not retrieve the values in the URL.

The url will look like this:

myApp/#page3?fid=Milk+Cheese+Butter

PHP is unable to get "?fid=".

I figure this is a problem with the way the URL is setup using JQuery mobile (single page). Any help resolving this problem would be greatly appreciated. Thank you

My Ajax (snippet):

request.onreadystatechange = function(){
    if((request.readyState==4) && (request.status==200 || request.status == 304)) {
        if(request.responseText!= undefined){
            window.location.replace('#page3?fid='+request.responseText+'');
        }
    }
}  

First PHP page:

<?php 
    include '../connect/connect.php';
    $ingredients = $_POST['ingredients'];
    if (empty ($ingredients) === false){
        foreach($ingredients  as $key => $ingre){
            if ($ingre != 'undefined'){
                $refine = substr($ingre, "4");
                $refined = mysqli_real_escape_string($con, $refine);
                echo $refined;
            }
        }
    }
?>

Second PHP page:

<?php
    if (isset($_GET['fid'])) {
         echo 'yes';
    } else {
        echo 'no';
    }
 ?>
6
  • 1
    It appears that you have the get string after a hash sign. PHP doesn't get anything after the hash sign. That is stripped out by the browser and never even sent to the server. Commented Nov 11, 2014 at 19:12
  • Yes, that's what I figured. But JQuery mobile requires that the # be there to navigate between pages. ...Is there a way around this? Commented Nov 11, 2014 at 19:14
  • Parse hash string in your js and get vars from it Commented Nov 11, 2014 at 19:14
  • 1
    The hash should be at the back, so the proper url would be myApp/?fid=Milk+Cheese+Butter#page3 Commented Nov 11, 2014 at 19:16
  • 1
    Thank you @GolezTrol! You the man. ...I've been trying to make this work for hours. Commented Nov 11, 2014 at 19:20

1 Answer 1

1

The hash (everything starting from the # character) is not sent to the server. The hash should be at the end of the url, after the so called query string, so the proper url would be:

myApp/?fid=Milk+Cheese+Butter#page3
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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