2

Using the ArcGIS for JavaScript API 3.19, I'm submitting a job to the ExtractData geoprocessing service at:

https://analysis7.arcgis.com/arcgis/rest/services/tasks/GPServer/ExtractData/submitJob

The job is submitted and run successfully, and the output is created in my ArcGIS Online root folder.

However, I can't figure out how to get the response back from the server. When I submit the job, the JavaScript console reports 2 errors:

SEC7127: Redirect was blocked for CORS request.

SCRIPT7002: XMLHttpRequest: Network Error 0x800c0014, A redirection problem occurred.

This sort of makes sense to me, because the server issues a redirect to the job page. I can see that the server responds with a status of 303, and includes the URL to the job in the response. However, the code that I have to handle the response (see below) is never called.

var url = _extractDataURL +
    "?inputLayers=" + inputLayers +
    "&extent=" + extent +
    "&clip=" + clip +
     "&dataFormat=" + dataFormat +
     "&outputName=" + outputName +
     "&context=" + context +
     "&f=" + f +
     "&token=" + IdentityManager.credentials[0].token;

var xmlHTTPRequest = new XMLHttpRequest();
xmlHTTPRequest.onreadystatechange = function () {
    if (xmlHTTPRequest.readyState == 4 && xmlHTTPRequest.status == 200) {
        console.log(this.responseText);
    }
}

xmlHTTPRequest.onload = function () {
    console.log(this.responseText);
}

xmlHTTPRequest.open("GET", url, true);
xmlHTTPRequest.send();

How can I configure things so that the redirect (the correct response) doesn't cause the CORS error, and so that I can handle the response and get the URL to the job?

  • 1
    have you tried using "jsonp" as your dataType in the javascript ajax call? – Brad Feb 7 '17 at 16:29
  • You said you're using the ArcGIS JS API 3.19 - can you use esri/tasks/Geoprocessor instead of rolling your own XMLHttpRequest? Not sure if it'll solve your problem but may make your code a bit simpler. – GavinR Feb 8 '17 at 14:26
  • @Brad jsonp isn't a supported data type for this operation, but I tried with f=json, and that worked: no errors and the response returned correctly. Interesting ... so why does CORS allow a JSON response but not an HTML response? – Jonathan Bailey Feb 8 '17 at 15:38
  • 1
    I should have paid closer attention. jsonp is not needed since you are using CORS... json is just text so it wouldn't try to redirect. – Brad Feb 8 '17 at 16:20
  • @GavinR I can run the job using esri/tasks/Geoprocessor: the result is created successfully. However, i end up with a different problem. The status callback returns an error: "Unable to get property 'length' of undefined or null reference" despite the fact that I've provided all of the parameters defined at: developers.arcgis.com/rest/analysis/api-reference/… and the job executing successfully. – Jonathan Bailey Feb 8 '17 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.