user9804375
user9804375

Reputation:

Passing PHP values to jquery

I have this value getting in my php:

  <?php echo $city_name; ?>

I have a doubt passing this value to the jquery. I need to append this $cityname with the popular_hotels1.php. i need to append it here:

$("#content").load("popular_hotels1.php?city_name=city_name&page=1", Hide_Load());

My complete jquery is as follows:

 $(document).ready(function(){

//Display Loading Image
function Display_Load()
{
    $("#loading").fadeIn(900,0);
    $("#loading").html("<img src='bigLoader.gif' />");
}
//Hide Loading Image
function Hide_Load()
{
    $("#loading").fadeOut('slow');
};

 //Default Starting Page Results

$("#pagination li:first").css({'color' : '#FF0084'}).css({'border' : 'none'});

Display_Load();

$("#content").load("popular_hotels1.php?page=1", Hide_Load());
//Pagination Click
$("#pagination li").click(function(){

    Display_Load();

    //Loading Data
    var pageNum = this.id;

    $("#content").load("popular_hotels1.php?page=" + pageNum, Hide_Load());
});

});

Upvotes: 0

Views: 81

Answers (3)

MaunashJani
MaunashJani

Reputation: 129

You can embed the php code in a span tag having an id, then use the same id to call in jQuery code.

PHP Code:

<span id="demo"><?php echo $city_name; ?></span>

jQuery Code:

var data = $("#demo").html();

$("#content").load("popular_hotels1.php?city_name=" +data + "&page="+pageNum, Hide_Load());

Upvotes: 0

Syno
Syno

Reputation: 1136

you set the php variable in a jquery variable as following:

var cityName = <?php echo $city_name; ?>

in your code:

$("#content").load("popular_hotels1.php?city_name=" + cityName + "&page=" + pageNum, Hide_Load());

Upvotes: 1

Gaurav Kandpal
Gaurav Kandpal

Reputation: 1330

Put your jquery code in php file after That you can directly use it like.

$("#content").load("popular_hotels1.php?city_name= <?php echo $city_name; ?>&page=1", Hide_Load());

Upvotes: 0

Related Questions