Any body has any idea how to encode a value which has comma(,) or any other special character in javascript and then decode the value in a different php page?
javacript code for send values through url
function search(){
var city_val = $('.city-selection').val();
var venue_val = $('.venue-selection').val()
var function_val = $('.function-selection').val();
var loadpage = "/data/scripts/search_decor.php?city="+city_val+"&venue="+venue_val+"&function="+function_val;
$('#main_content').load(loadpage, function() {});
}
php code for retreiving values from url
$city = $_GET['city'];
$venue = $_GET['venue'];
$function = $_GET['function'];
On the javascript side you need to use encodeURIComponent()
.
For example:
var city_val = encodeURIComponent($('.city-selection').val());
On the php side you should use urldecode()
. For example:
$city = urldecode($_GET['city']);
Check the links for encodeURIComponent() and urldecode().
Use encodeURIComponent(string)
in JS
and string urldecode ( string $str )
in PHP
function search(){
var city_val = $('.city-selection').val();
var venue_val = $('.venue-selection').val()
var function_val = $('.function-selection').val();
var loadpage = "/data/scripts/search_decor.php?city="+encodeURIComponent(city_val)+"&venue="+encodeURIComponent(venue_val)+"&function="+encodeURIComponent(function_val);
$('#main_content').load(loadpage, function() {});
}
$city = urldecode($_GET['city']);
$venue = urldecode($_GET['venue']);
$function = urldecode($_GET['function']);