You need to sign in to do that
Don't have an account?

How to get response back from VF when using XMLHttpRequest?
Hi,
I have a VF page that simply outputs some text:
<apex:page controller="myController" contentType="text/javascript" showHeader="false"> some garbage text </apex:page>
Then I have a JavaScript that uses XMLHttpRequest to make a request to the above VF page:
var url = "http://na4.salesforce.com/apex/myPage"; xmlhttp.open('GET', url, true); xmlhttp.send(null);
Before making the request I make sure that I'm logged in with my salesforce account (so that I don't need to pass user/pass thru the url). The problem is that, I never get anything back. xmlhttp.status is always 0 and xmlhttp.responseText is always blank. Firebug shows the status of the GET request as 200 OK.
Any ideas how I should make REST calls to a VF page and get the response back? Thanks!!
I haven't tested this, but I suspect the issue may be that you need to URL encode the startURL param. Without doing so, param2 and param3 would be interpreted as params for login.jsp, and not for your myPage.
All Answers
Could you include the full javascript for the page making the request? Your example seems incomplete.
Also, where is the page making the request hosted? It is a VF page as well? If it's on a different domain you could be running into a cross domain issue.
...stephan
I've switched to dojo and this is what I have:
I don't get anything back. This works however if instead of the salesforce url I pass in the path to some text file on my local machine.
Again -- this could be a cross domain issue. Generally the browser only lets you make an XHR request from/to the same domain.
You may want to try this in Firefox with Firebug installed to see if any errors show up in the console.
...stephan
You're right, that was an xdomain issue. So I'm now using dojox.io.windowName.send but now there's a new issue. My controller doesn't seem to get called when I pass the following url to dojox.io.windowName.send:
This call basically returns me the content of my VF page without the controller ever running (I know this because in the constructor of the controller I set some value on the page that doesn't show up in the callback result).
Any thoughts on that?
I haven't tested this, but I suspect the issue may be that you need to URL encode the startURL param. Without doing so, param2 and param3 would be interpreted as params for login.jsp, and not for your myPage.
I think you're right. Thanks!!