What happens is, the page is loaded, and then I cycle through all of the hidden text boxes with a certain class to get their values. The values are a combination of the type (either "e" for event or "v" for venue) and the resource ID in my database for that particular event or venue. I then take those values and send them to a PHP script via AJAX, which returns a JSON object with longitude, latitude, and title for the event or venue. I then use this information to add a marker to the google map at the bottom of the page.
The problem is sometimes I get an AJAX error on one particular round of this process. I've checked to make sure the variables with the type + ID information are all getting set correctly (they are displayed in a JS alert box), and to make sure that the AJAX call is running the correct amount of times. But for some reason, sometimes either 1 or 2 of the barcrawl stops produce an error in this process, and are thus not added to the google map. What's really frustrating me is that when I try to restart the process using a button I added to the page for testing purposes, I get the error on the exact same barcrawl stop. However, I can't for the life of me find any difference in the information for the error-producing stop, and the other stops that run the process successfully.
I'm not too familiar with the technical aspects of AJAX (I know how to do it, but I'm not really sure how it works besides the basics), so this may be an issue with too many calls to the same page, or something of that nature. However, because I get the error at the same point in the process each time, corresponding to the same barcrawl stop, my intuition tells me there is something wrong with the data for that stop that I'm sending through the AJAX call.
Does anyone have any ideas? You can check out the page I'm working on here. If you don't get the error, you can refresh the page and it will load new stops, one of which will typically give an error after a few refreshes. Thanks in advance. As you can imagine, this is very frustrating.
Here's the relevant code:
jQuery AJAX call:
Code: Select all
$(".barcrawl-stop-id").each(function(){
info = $(this).val();
$.ajax({
url:"/handlers/ajax/barcrawl_map_info.php",
beforeSend: function() {
alert("Running AJAX on " + info);
},
data:{info: info},
dataType:"json",
method:"GET",
success:function(data) {
var point = new GLatLng(data.lat, data.lng);
var markerOptions = { title:data.name };
var marker = new GMarker(point, markerOptions)
map.addOverlay(marker);
},
error:function() {
alert("AJAX error");
}
});
});
Code: Select all
<?php
session_start();
require '../../config/config.php';
require NITEFLIP_ROOT_DIR . "/includes/includes.php";
$info = $_GET['info'];
$type = substr($info, 0, 1);
$id = substr($info, 1);
if($type == 'e') {
$display = new display("table=events&id=$id");
}
else {
$display = new display("table=venues&id=$id");
}
$result = mysql_fetch_array(mysql_query($display->compile_query()));
$lat = $result['latitude'];
$lng = $result['longitude'];
$name = $result['name'];
echo "{lat: '$lat', lng: '$lng', name: '$name'}";
?>