-1

My code is as follows

$(document).ready(function(){

      var bed = $( "input[name=bed]:checked" ).val();
      var bud = $( "input[name=bud]:checked" ).val();
      var loc = $("#autocomplete").val();

      $("#search_list").load('main_frame2.php?bed='+bed+'&bud='+bud+'&loc1='+loc);
    });

In main_frame2.php

<?
    session_start();

    echo $loc = $_GET['loc1']   ;
    echo $bed = $_REQUEST['bed']    ;
    echo $bud = $_REQUEST['bud']    ;

?>

I am getting the values of bed and bud. But m not getting for loc. But if i use alert inside jquery function m getting loc name which is not passing to main_frame2.php

leo.fcx
  • 6,137
  • 2
  • 21
  • 37
namratha
  • 191
  • 4
  • 11

7 Answers7

1

load sends a GET request, yet your PHP is looking in the $_POST for the loc1 value. Try using $_REQUEST or better yet, $_GET to retrieve your querystring values.

<?
    session_start();
    echo $loc = $_GET['loc1'];
    echo $bed = $_GET['bed'];
    echo $bud = $_GET['bud'];
?>
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
1

jQuery load does a GET. So instead of getting $loc with $_POST['loc1'];, try $_GET['loc1'];

Andreas Furster
  • 1,558
  • 1
  • 12
  • 28
1

Use $_GET instead of $_POST, your are not posting but getting the data.

Explanation of jQuery

The POST method is used if data is provided as an object; otherwise, GET is assumed.

Barry
  • 3,683
  • 1
  • 18
  • 25
1

Replace first line of code in PHP file with

echo $loc = $_GET['loc1'];

Amy
  • 4,034
  • 1
  • 20
  • 34
1

If you read the documentation, it says

.load( url [, data ] [, complete ] )

Documentation

It means you can pass data in second arguement in JSON format. Also, .load internally uses GET method so modify your PHP Code accordingly.

Apul Gupta
  • 3,044
  • 3
  • 22
  • 30
1

Try this:

jQuery

$(document).ready(function(){
      var bed = $( "input[name=bed]:checked" ).val();
      var bud = $( "input[name=bud]:checked" ).val();
      var loc = $("#autocomplete").val();

      $("#search_list").load('main_frame2.php', {bed: bed, bud: bud: loc: loc}, function(){
           console.log('PHP Loaded');
      });
});

Then on your PHP:

<?
    session_start();

    echo $loc = $_GET['loc']  ; <<== since you are getting data from URL
    echo $bed = $_REQUEST['bed']; <<== you can also use $_GET['bed']
    echo $bud = $_REQUEST['bud']; <<== you can also use $_GET['bud']

?>
jpcanamaque
  • 1,049
  • 1
  • 8
  • 14
1

You're passing the variables in the URL. This implies you're making a GET request to main_frame2.php.

From the documentation $_REQUEST returns all the HTTP Request variables :

An associative array that by default contains the contents of $_GET, $_POST and $_COOKIE

So either you access all your variables as $_REQUEST['foo'] or $_GET['foo'].

A relevant post on SO that might clarify things further. Hope it gets you started in the right direction.

Community
  • 1
  • 1
Vivek Pradhan
  • 4,777
  • 3
  • 26
  • 46