Passing several values with AJAX?
This isn't working:
$.ajax({url: "PStoreZoomArea.php", type: "get", data: {"mapza": mapZoomArea, "mapc": mapCenter, "mapz": mapZoom}})
The code in the PHP-file:
$_SESSION['mapZoomArea'] = (isset($_GET['mapz开发者_C百科a']) ? $_GET['mapza'] : '1');
$_SESSION['mapCenter'] = (isset($_GET['mapc']) ? $_GET['mapc'] : '(55.67893946343211, 12.568359375)');
$_SESSION['mapZoom'] = (isset($_GET['mapz']) ? $_GET['mapz'] : '11');
If I only send one value it's working, but not with several. I have also tested to use a AJAX call for each value, but not working either. What could be wrong?
If you are using GET, change your ajax block to this instead:
$.ajax({
url: "PStoreZoomArea.php",
type: "GET",
dataType: "text",
data: "mapza=" + mapZoomArea + "&mapc=" + mapCenter + "&mapz=" + mapZoom
});
Check out JQuery's official documentation on .ajax
http://api.jquery.com/jQuery.ajax/
$.ajax({
url: "PStoreZoomArea.php",
type: "GET",
data: {"mapza": mapZoomArea,
"mapc": mapCenter,
"mapz": mapZoom
}
});
and your php code needs to be either what you have already or instead of GET use REQUEST also look in firebugs console what the request looks like to make sure it hits the correct php script and all the parameters are displaying
$_SESSION['mapZoomArea'] = (isset($_REQUEST['mapza']) ? $_REQUEST['mapza'] : '1');
$_SESSION['mapCenter'] = (isset($_REQUEST['mapc']) ? $_REQUEST['mapc'] : '(55.67893946343211, 12.568359375)');
$_SESSION['mapZoom'] = (isset($_REQUEST['mapz']) ? $_REQUEST['mapz'] : '11');
精彩评论