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
Paulo CastroPaulo Castro 

VF and REST requests

Hi,

 

 I have this VF page that uses some AJAX code to send/receive data using JS XMLHttpRequest call. This page exchange JSON data with SF server.

 The issue is when I make the first call to the server address. On the first call I send to SF address:

 

 https://xxx.na6.visual.force.com/apex/MyJSON?core.apexpages.devmode.url=1 

 

 the request, but it redirects me to this other page:

 

 https://na6.salesforce.com/visualforce/session?url=https%3A%2F%2Fxxx.na6.visual.force.com%2Fapex%2Fxxx__MyJSON%3Fcore.apexpages.devmode.url%3D1

 

 and then redirects me again to the original address, to finally show the result. It seems that SF is authenticating me again, even when I'm alredy authenticated.

 

 This redirection is making my JS not work correctly. So, to be able to view the data, first I have to manually call the original address and then refresh my VF page.

 But I can't ask to my users to do this before open this page :)

 

 Anyone knows how to solution it?

 

 Tnx in advance

 

 Best regards

 

 

 PH

 

 

Paulo CastroPaulo Castro

No one had similar issue??

 

How you guys, using ExtJS, MooTools, YUI, or any other AJAX lib in a VF page, are doing to comunicate to SF server without refreshing the entire page window?

 

I thought the only way was using REST and JSON to exchange data, with a VF page doing this interface.

 

I saw the webservices API but I don't want to ask to my users to fill their id/passwd again to be able to execute a webservice call in this VF page.

Mike LeachMike Leach
I had a similar issue using JQuery. apex:actionFunction appears to be the best way to call a controller method that asynchronously returns JSON.
Paulo CastroPaulo Castro

Hi Cubic,

 

 thank you for your reply.

 

 How do you call an apex:actionFunction from a external JS?

 

 best regards

 

Mike LeachMike Leach

The 'name' attribute on apex:actionFunction is used to generate a javascript proxy stub to the controller.

 

So a JQuery event can wired up as follows: 

<apex:form> <apex:actionFunction name="doSomething" action="{!DoSomething}" /></apex:form><script> $(function() { $("#doSomethingLink").click( function() { doSomething(); }); });</script><a id="doSomethingLink" href="#">Do Something</a>

 

 

Paulo CastroPaulo Castro

thank you very much!