我的阿贾克斯POST快到了作为一个错误即使我回到200 [英] My Ajax POST is coming up as an error even though I am returning 200
问题描述
我想提出一个AJAX张贴到泽西岛的资源。我建立一个图像并将其返回。问题是,不管我回什么样的地位,阿贾克斯认为这是一个错误。其实我可以使用(通过error.responseTest)的错误信息,并能正常工作。但它是丑陋的。我怎么回使之成功?我已经回到正常(200),接受(202)和创建(201)。所有这些给我一个错误信息,但在我的控制台网络选项卡中,我获得了成功(绿色适当的状态)。
我回到这样的:
返回Response.status(Response.Status.ACCEPTED).entity(图).header(内容类型,图像/ PNG)建立()。
我的JS code:
$。阿贾克斯(Monocle.config.Sightline.jobUrl +/视线,{
键入:POST,
过程数据:假的,
数据:JSON.stringify({
LAT1:Monocle.Sightline.BBOX(功能,2),
Long1:Monocle.Sightline.BBOX(特征,1),
LAT2:Monocle.Sightline.BBOX(特征,4),
Long2:Monocle.Sightline.BBOX(功能,3),
OrgLat:observerCoords [0] .lat,
OrgLong:observerCoords [0] .lon,
ObHeight:feature.attributes.observerHeight,
TargHeight:feature.attributes.targetHeight,
OuterRadius:feature.attributes.outerRadius,
LVA:feature.attributes.lowerVertAngle,
UVA:feature.attributes.upperVertAngle,
sAzimuth:feature.attributes.startAzimuth,
eAzimuth:feature.attributes.endAzimuth,
输出类型:MAX
}),
的contentType:应用/ JSON
数据类型:JSON,
成功:函数(结果){
VAR图形=新OpenLayers.Layer.Image(
Monocle.currentWidget.name +目的地+ featurenum,
数据:图像/ PNG; BASE64,+结果,
新OpenLayers.Bounds(Monocle.Sightline.BBOX(特征,1),Monocle.Sightline.BBOX(功能,2),Monocle.Sightline.BBOX(功能,3),Monocle.Sightline.BBOX(特征,4)),
新OpenLayers.Size(580,288),
{isBaseLayer:假的,
不透明度:0.3,
displayOutsideMaxExtent:真
});
feature.legionObject =图形;
graphic.relatedlayer = Monocle.currentWidget.name +目的地+ featurenum;
Monocle.Map.map.addLayer(图形);
},
错误:函数(ERRMSG){
// TODO:真的处理任何错误
}
});
设置数据类型:JSON,
意味着你的反应是将 JSON
,它是不是会导致错误所以只是将其删除。
也就是你的图像数据进行Base64的EN codeD做一个数据的URI。
I am making an AJAX post to a Jersey Resource. I build an image and return it. The issue is, no matter what status I return, Ajax thinks it is an error. I can actually use the error message (via error.responseTest) and it works fine. But it is ugly. What do I return to make it a success? I have returned OK(200), Accepted(202) and Created(201). All of them give me an error message but in my Console Network tab, I get a success (green with the proper status).
I am returning it like this:
return Response.status(Response.Status.ACCEPTED).entity(image).header('Content-Type',"image/png").build();
My JS code:
$.ajax( Monocle.config.Sightline.jobUrl + "/sightline", {
type: "POST",
processData: false,
data: JSON.stringify({
Lat1: Monocle.Sightline.BBOX(feature,2),
Long1: Monocle.Sightline.BBOX(feature,1),
Lat2: Monocle.Sightline.BBOX(feature,4),
Long2: Monocle.Sightline.BBOX(feature,3),
OrgLat:observerCoords[0].lat,
OrgLong:observerCoords[0].lon,
ObHeight: feature.attributes.observerHeight,
TargHeight: feature.attributes.targetHeight,
OuterRadius: feature.attributes.outerRadius,
LVA: feature.attributes.lowerVertAngle,
UVA: feature.attributes.upperVertAngle,
sAzimuth: feature.attributes.startAzimuth,
eAzimuth: feature.attributes.endAzimuth,
outputType: "MAX"
}),
contentType: "application/json",
dataType: "json",
success: function( results ){
var graphic = new OpenLayers.Layer.Image(
Monocle.currentWidget.name + " Destination " + featurenum,
"data:image/png;base64," + results,
new OpenLayers.Bounds(Monocle.Sightline.BBOX(feature,1), Monocle.Sightline.BBOX(feature,2), Monocle.Sightline.BBOX(feature,3),Monocle.Sightline.BBOX(feature,4)),
new OpenLayers.Size(580, 288),
{ isBaseLayer: false,
opacity: 0.3,
displayOutsideMaxExtent: true
});
feature.legionObject = graphic;
graphic.relatedlayer = Monocle.currentWidget.name + " Destination " + featurenum;
Monocle.Map.map.addLayer(graphic);
},
error: function(errMsg) {
// TODO: really handle any errors
}
});
Setting dataType: "json",
means that your response is to be json
which it isn't that would cause the error so just remove it.
Also is your image data has to be base64 encoded to make a data uri.
这篇关于我的阿贾克斯POST快到了作为一个错误即使我回到200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!