Reputation: 1696
I need get (date) parameter form URL by php but after load "step-02.php" by .load
jQuery.
For example:
http://localhost:8000/selectRoom?hotelID=100&date=2016-11-08&night=5
I get the 2016-11-08
value from URL by php is $_GET['date']
but after I load step-02.php
with jQuery this code $_GET['date']
does not work.
$(function () {
$('#Step-01').hide();
$('#Step-02').show();
$('#Step-02').load('step_02.php');
})
HTML in step-02.php
:
<div class="alert alert-success">
// This line gives an error and not work!
<?php echo $_GET['date']; ?>
</div>
Upvotes: 1
Views: 1973
Reputation: 4671
if i understand well at first you call this url , with these parameters : http://localhost:8000/selectRoom?hotelID=100&date=2016-11-08&night=5
, that is why in your PHP file you can get the parameters , $_GET['hotelID']
, $_GET['date']
and $_GET['night']
.
The url does not change to a new one , it remains as it was : http://localhost:8000/selectRoom?hotelID=100&date=2016-11-08&night=5
,
and that is the problem! The php file step_02.php , did not get any parameters from the client on the server request , so it does not recognise any parameter , although they are on the url.
A. You can get the url by : $_SERVER['HTTP_REFERER']
, which is going to give you all the url as it is, and by explode("?", $_SERVER['HTTP_REFERER'])
you are going to get the part of the url that has the parameters, after that you can use explode again..
B. you can pass the parameters you wish while you execute the ajax call to the server, and get them with $_GET['parameter'
], like so:
data = {'hotelID':100,'date':2016-11-08,'night':5};
$.ajax({
cache: false,
url : url,
type: "GET",
data : data,
beforeSend: function( xhr ) {
//load your spinner img
},
success : function(data, textStatus, jqXHR){
//get response from server
},
error : function(xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
$('#Step-02').load('path', 'key=value');
Hope helps, good luck.
Upvotes: 2
Reputation: 480
http is stateless so unless you pass the date back in the ajax request, or save it to the session, the server has no way of remembering what you've told it previously.
Put this in step1.php somewhere
<input type="hidden" id="date-input" value="<?php echo $_GET['date']?>" />
Then do this:
$(function () {
var date = $('#date-input').val();
$('#Step-01').hide();
$('#Step-02').show();
$('#Step-02').load('step_02.php?date='+date);
})
Upvotes: 2
Reputation: 6628
Your question is not clear but I assume that you want to get the date value after load.
Use callback()
$('#Step-02').load('step_02.php', function(response, status, xhr) {
alert( "Load was performed." );
console.log(response);
});
Upvotes: 1