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
WEN JIEWEN JIE 

Use jquery.ajax in Visualforce

Hi,

 

I want to use jquery.ajax method to send my request to an external service in Visualforce.

Have a look with my javascript : 

 

$j.ajax({
type:'POST',
url:'http://myexternalurl',
data:{"userName":"xxxxxx","password":"xxxxxx","securityToken":"xxxxxx"},
contentType : 'application/json',
dataType:'json',
success:function(data){
alert("success");
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert("textStatus : "+textStatus);
alert(XMLHttpRequest.readyState);
alert("status : "+XMLHttpRequest.status);
}
});

 

When this code execute, I receieve the response with error method:

textStatus : error

XMLHttpRequest.readyState : 0
XMLHttpRequest.status : 0

 

I don't  konw whether there are some error in my code, so does anyone have experiences about use jquery.ajax in Visualforce or how to post a request to an external service in Visualforce?

 

Thanks!

 

bvramkumarbvramkumar

Did you add "http://myexternalurl" in Remote Access? did you alert "errorThrown" to see what was the issue?

WEN JIEWEN JIE

Hi bvramkumar,

 

I try to add my url in Remote Access,  but I can't pass the Callback RUL validation rule, it said "Error: Cannot be an HTTP url", and I add http url successful before.

I just alert these status :

textStatus : error

XMLHttpRequest.readyState : 0
XMLHttpRequest.status : 0

 

Thanks!

bvramkumarbvramkumar

Try adding your URL under in "Remote Site Settings".  go to setup>Security Controls>Remote Site Settings

Siddharth Birari.ax1164Siddharth Birari.ax1164

Since the callout is being made through client side, it is not required to configure the url in 'Remote site Settings'.

I am able to make the callout however I am not able to jump to the call back function..

 

I get the response if verified through the developer conosole..