我设置了url映射以接收GET和POST请求。我正在使用Prototype AJAX。这是我的功能:
function savePrefs(){
var user = document.getElementById('username').innerHTML;
var bounds = window.map.getExtent();
var Lat = bounds.left + (bounds.right - bounds.left) / 2;
var Long = bounds.bottom + (bounds.top - bounds.bottom) / 2;
var Zoom = window.map.getZoom();
var json = new Object;
var url = "Prefs";
json.username = user;
json.lat = Lat;
json.long = Long;
json.Zoom = Zoom;
json = JSON.stringify(json);
alert(json);
new Ajax.Request(url, {
method:'post',
contentType:'application/json',
postBody:json,
asynchronous:true,
onSuccess: function (req) {
alert(req);
}
}); }
我在控制台中一直收到404错误。但是当我加载页面时,我会执行GET请求并且响应正常。有什么想法吗?