2011-03-17 192 views
1

我想弄清楚我在做什么错在这里。基本上我试图从获得一个成功的回调:jQuery Ajax问题

http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/project?f=pjson&inSR=4326&outSR=102113&geometries={"geometryType":"esriGeometryPoint","geometries":[{"x":-117,"y":34}]} 

当粘贴到浏览器中,我得到的数据,当我在做这在Javascript中,它调用错误处理程序不起作用。有任何想法吗?我用小提琴来比较请求,发现真的没有区别。

$.ajax({ 
    type: 'GET', 
    url: 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/project?f=pjson&inSR=4326&outSR=102113&geometries={"geometryType":"esriGeometryPoint","geometries":[{"x":-117,"y":34}]}', 
    success: function(data){ 
     alert('success'); 
    }, 
    error: function(jqXHR, textStatus, errorThrown){ 
     alert('error'); 
    } 
}); 
+4

在没有任何反应,不会因为你的错误功能工作不工作时被调用,不工作的在你的成功功能被称为但没有数据或不工作,因为在任何时候你尝试它你的电脑着火?或者其他“不起作用”。 – Chris 2011-03-17 15:04:26

+0

在调用错误处理程序时不起作用。 – 2011-03-17 15:06:50

+0

@LB - 错误的textStatus和响应代码是什么? – justkt 2011-03-17 15:07:30

回答

0

你很可能http://api.jquery.com/jQuery.getJSON/并设置JSONP回调

$.getJSON('http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/project?f=pjson&callback=?&inSR=4326&outSR=102113&geometries={"geometryType":"esriGeometryPoint","geometries":[{"x":-117,"y":34}]}', function(res) 
{ 

}); 

类似的东西可能会奏效,注意到&回调=?在添加的查询字符串中。

4

添加JSONP paremeter:

$.ajax({ 
    type: 'GET', 
    dataType : 'jsonp', 
    url: 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/project?f=pjson&inSR=4326&outSR=102113&geometries={"geometryType":"esriGeometryPoint","geometries":[{"x":-117,"y":34}]}', 
    success: function(data){ 
     alert('success'); 
    }, 
    error: function(jqXHR, textStatus, errorThrown){ 
     alert('error'); 
    } 
}); 
+0

就是这样。谢谢。 – 2011-03-17 15:10:31

2

除非你的网站是在sampleserver1.arcgisonline.com,你正在运行到跨站点脚本的担忧。

为了减轻他们,你可以:

  1. 在自己的服务器上运行通过代理您的要求为您的网站。
  2. 使用JSPONP,如果您要请求信息的域支持它。
0

我想我可能有同样的问题。从我的角度来看,ESRI似乎有一种理解状态代码的有趣方式。

问题是,您从服务器收到200回,这应该表示成功。但是,您从ESRI收到的传输是错误的。我有我的ESRI的Ajax调用要做的就是分析响应...

parse: function(response) { 
    if (response.error) { //If there is a server error, it will find it here. 
     this.searchError(response.error); //I would then send to the error function. 
    } 
    return response.features 
}