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
mbbendermbbender 

Trouble with remoteFunction AJAX proxy

Does anyone have a good debug environment or resources for inspecting and/or walking through the cross-domain information transfer?
 
I'm using the following code and am having troubles determining if my php script is even being called and if so what I should be expecting in php.
 
Code:
function sendObj(objectToSend) {
sforce.debug.log("Sending object: " + {"contactContainer":objectToSend});
try{
sforce.connection.remoteFunction(
{
url: "http://mydomain.com/middleware.php",
requestHeaders: {"Content-Type": "application/x-www-form-urlencoded"},
requestData: {"contactContainer":objectToSend},
mimeType: "text/xml",
method: "POST",
onSuccess: function(response) {
document.getElementById("result").value = response.textContent;
},
onFailure: function(response) {
document.getElementById("result").value = "Failed " + response;
}
}
);
}catch(e){
alert("Error in sendObj: " + e);
}
} // end sendObj

 
Ron HessRon Hess
you can trace the client side using firebug, on ther server side i guess you can write to the server log?

i think request data is a string not a javascript object.
mbbendermbbender
Do you know how I can send an object instead of a string?
Ron HessRon Hess
i think you can use
 
yourobject.toString();

which will generate JSON format of that object.
then your server will have to unwrap/unpack the JSON format

for debugging, you can just send "hello world" to make sure your PHP can see the data.
mbbendermbbender

So I'm trying hello world, but its not invoking my php script.  I have a feeling that this remoteFunction() is not working.

Code:

sforce.connection.remoteFunction(
 {
  url: "http://subdomain.mydomain.com/mbbtest.php",
  requestHeaders: {"Content-Type": "text/xml","SOAPAction": "\"\""},
  mimeType: "text/xml",
  requestData: "hello world",
  method: "POST",
  onSuccess: function(response) {
          ;
  },
  onFailure: function(response) {
          ;
  }
 }
);


 

I've registered  http://subdomain.mydomain.com as an acceptable URL in my salesforce configurations. Not sure why this isn't calling my mbbtest.php file. Not sure how to debug it either. I also can't find to much info about the remoteFunction() other than an article using it.

mbbendermbbender
I added a debug statement to the failure and success functions and am getting this:
 

400 Endpoint protocol(http/https) mismatch: http://subdomain.mydomain.com/mbbtest.php

 

any ideas why?

I have it configured for http everywhere I can find.

mbbendermbbender
Found a good post that helped me out. I have to access salesforce with http for it to work.


I have another question.


How do I access the requestHeader from within php?
Ron HessRon Hess
i don't know, not a big PHP guy, sorry.
i'm sure you can get a response on the PHP developer board.
ShinShin
Above "Endpoint Protocol Mismatch" error is caused by current security restriction of the AJAX Proxy, they said before.
http://community.salesforce.com/sforce/board/message?board.id=ajax_toolkit&message.id=3036

And I posted an enhance request to ideaexchange. If you agree with me please vote from here.
http://ideas.salesforce.com/article/show/70257/Allow_http_web_services_callout_in_AJAX_Proxy

mbbendermbbender
Shin, I found your post. That was the post I was referring to which helped me at least understand the problem. I voted for you immediately after finding the post!

I'll try the php dev boards. Thanks for all the help.