function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Greg HGreg H 

Status Code of Remote Server

I need to check the status code of a remote URL prior to allowing a POST.  Since this POST would be to a domain other than salesforce, I believe I need to use the remoteFunction() call in the AJAX toolkit.  I've set this up using the proxy proxy settings but cannot seem to figure out how to get only the "status code" piece of the response.
 
Code:
function getResponse() {
 sforce.connection.remoteFunction({
  url : "http://remote.location.com/specific/page",
  method : "GET",
  mimeType : "text/xml",
  onSuccess : function(response) {
   document.getElementById("responseTXT").innerHTML = "<div style=\"font-weight: bold; color: #FF0000;\">SUCCESS!!!!</div><div>"+response+"</div>";
  },
  onFailure : function(response) {
   document.getElementById("responseTXT").innerHTML = "<div style=\"font-weight: bold; color: #FF0000;\">Failed:</div><div>"+response+"</div>";
  }
 });
}

If you look at my function from above, you can see that I can get back "response" and when it does return it literally displays the content of the remote URL in the sControl.  But I was hoping I'd be able to get back something like "response.status" or "response.statusCode" and simply use that code to determine if I should allow for the POST later in the sControl.
 
Any help is appreciated,
-greg
cheenathcheenath
onSuccess is called when the status code is 200 else onFailure is called. So if you are
looking for status code 200 then you can check which method is called.

Otherwise you can modify connection.js    function _remoteFunctionCallback()

to call your onSuccess with the XHR. Something like:

   args.onSuccess(request.responseXML.documentElement, request);


Then in your callback:

  function mySuccessCallback(response, xhr) {
     alert(xhr.status);
  }

HTHs,