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
sf.freelancesf.freelance 

Is it possible to use the salesforce AJAX with visualforce pages deployed on Sites?

Hi

 

I created a VF page with Ajax. It can get fields value from SF with javascript.

 

All that works well in suck link: xxxx.salesforce.com/apex/xxxxxx. But after I put this VF page on sites, it can not get any data.

 

My VF page ajax code is as below:

 

try { sforce.connection.login("xxx@xxx.com", "xxxxpasswordxxxxsecurityToken");

alert("Login Success");

var result = sforce.connection.query("SELECT c.Id, c.Name, c.Email, c.Account.Name FROM Contact c");

  xxxxxxx some logic.

} catch(e) { alert(e); }

 It threw some error message:{faultcode:'UNKNOWN_EXCEPTION',faultstring:'UNKNOWN_EXCEPTION:Site under construction',}

In VF page, it can works well, but in site this line threw error

sforce.connection.login("xxx@xxx.com", "xxxxpasswordxxxxsecurityToken");

 

 

Who can help me?

 

Thanks


 

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert
Instead of using the API through AJAX to execute that query, why not use Apex controller associated to your VF page? That will also avoid you having to hardcode the username/password into your javascript which is probably not very secure.