I am trying to send a serialzed data to another php page like below:
$.ajax({
url:"get_more_news.php?x1="+'<?php echo $x1 ?>',
method: 'get',
success: function(data)
{
alert(data);
}
});
Here $x1 is a serialzed data. Now my concern is,
1.) Would it be a good practice to send the data like this. 2.) Would it create an issue if there is a single quotes in the serialzed data.(pls note that there are also quotes on get_more_news.php?x1="+'')
If you need to pass some data I suggest you no use json
format. Here how it can look like:
$.ajax({
url:"get_more_news.php",
method: 'get',
data: <? echo json_encode($x1) ?>,
success: function(data)
{
alert(data);
}
});
Where json_encode
function will help you to overcome/avoid difficulties with quotes.
Update:
Suppose you want to send array like:
$array = ['x1' => 'value', 'x2' => 'another_value'];
In js-part you use:
data: <? echo json_encode($array) ?>,
Then in your get_more_news.php
you can use this values as old plain $_GET
vars (as your method
is GET
):
echo $_GET['x1'];
echo $_GET['x2'];