1

ジャージー リソースに AJAX を投稿しています。イメージをビルドして返します。問題は、私がどのようなステータスを返しても、Ajax はそれをエラーと見なすことです。実際にエラー メッセージを (error.responseTest 経由で) 使用でき、問題なく動作します。しかし、それは醜いです。成功させるには何を返せばいい?OK(200)、Accepted(202)、Created(201)を返しました。それらのすべてでエラー メッセージが表示されますが、コンソールの [ネットワーク] タブでは成功 (適切なステータスの緑色) が表示されます。

私はこのようにそれを返しています:

    return Response.status(Response.Status.ACCEPTED).entity(image).header('Content-Type',"image/png").build();

私のJSコード:

$.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

        }
    });
4

1 に答える 1

1

設定は、エラーの原因とならないdataType: "json",応答であることを意味するため、削除してください。 また、データuriを作成するには、画像データをbase64でエンコードする必要があります。json

于 2013-04-19T20:22:04.457 に答える