시간에 jQuery를 사용하여 몇 건의 AJAX 요청을 수행했지만 어떤 이유로이 코드가 작동하지 않습니다.jQuery AJAX Request Error
내 코드는 사용자에게 위치를 물어보고 Google Maps API를 사용하여 위치 정보를 지정하고 가장 가까운 5 개의 상점을 사용자에게 반환합니다.
URL 매개 변수를 수동으로 입력 한 브라우저에서 아약스 요청에 의해 호출 된 페이지를 방문하면 정상적으로 작동합니다. www.domain.com/storelocator/geocode.php?address=xxxxxx
index.php를
<form id="storeform">
<input type="text" id="address" size="50"/>
<span><input id="submit" type="image" src="../images/btnsmall.jpg" value="Search" /></span>
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?libraries=geometry&sensor=false" ></script>
<script type="text/javascript">
$(document).ready(function() {
$('#storeform').submit(function() {
var address = $('#address').val();
var params = $('#storeform').serialize();
if (address == '') {
alert('Please enter a location');
}
$.ajax({
url: "geocode.php",
data: params,
dataType: 'html',
type: 'GET',
success: function(response){
$('#stores').html(response);
}
});
});
});
</script>
geocode.php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$db_conn = mysql_connect('xxxxxx', 'xxxxxx', 'xxxxx') or die('error');
mysql_select_db('xxxx', $db_conn) or die('error');
$address = $_GET['address'];
$earth_radius = 3959;
$ch = curl_init('http://maps.google.com/maps/api/geocode/json?address='.$address.'&sensor=false');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$geocode = curl_exec($ch);
curl_close($ch);
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$lng = $output->results[0]->geometry->location->lng;
$sql = "SELECT *, ($earth_radius * acos(cos(radians($lat)) * cos(radians(latitude)) * cos(radians(longitude) - radians($lng)) + sin(radians($lat)) * sin(radians(latitude)))) AS distance FROM stores HAVING distance < 25 ORDER BY distance LIMIT 5";
$result = mysql_query($sql);
$stores = '';
if (mysql_num_rows($result) > 0){
while($row = mysql_fetch_array($result))
{
$stores .= $row['town'].' - '.$row['name'];
$stores .='<br />';
}
}
else {
$stores = 'No results!';
}
echo $stores;
그것은 와서 너무 빨리 간다 때문에 방화범에 오류가 어렵다하지만 내부처럼 보인다 server error in geocode.php 어떻게 든.
또한 양식을 제출할 때 내 URL에 이상한 x 및 y 매개 변수가 표시됩니다 (예 :
http://www.domain.com/store-locator/index.php?x=13&y=11
나는 이유를 모릅니다.
도움을 주시면 감사하겠습니다.
을 클릭하여 불을 지르고의 "지속"및 해당 페이지에있는 경우, 오류가 표시됩니다 .. 그리고 in url –
Firebug Console에서 "Persist"버튼을 클릭하면 URL 변경시 데이터가 지워지지 않습니다. – Jasper
이미지 제출을 사용하기 때문에 브라우저는 이미지의 클릭 x 및 y 좌표에 대한 GET 매개 변수를 자동으로 추가합니다. 따라서 귀하의 예에서 이미지 버튼은 (13,11) –