I created a VF page published on Site (http://trapptosemplify-developer-edition.eu2.force.com/TR/Login)
On the page there is a button "Accedi" which trigger a script using RemoteAction for the LOGIN (Code on bottom).
The same code inside SFDC work correctly, but the on site doesn't work. I does not understand why this happen. I published all pages on Site and setted the visibility for all profiles, the same for the controller…
anyone can help me?
THNK
K.
JSCRIPT:
<script type="text/javascript">
j$ = jQuery.noConflict();
function loginUser() {
var name = j$('#name').val();
var password =j$('#password').val();
var namespace = 'TRRemoteActions.loginAccount';
alert("ok");
Visualforce.remoting.Manager.invokeAction(namespace, name, password, function(result, event){
if (event.status) {
window.location = result;
} else {
j$('#error').show();
j$('#error').html(event.message);
}
},
{escape: true}
);
}
</script>
APEX
@RemoteAction
global static pagereference loginAccount(String userName, String userpassword) {
String UserId=null;
List<Account> loginAccount = new List<Account>();
try{
loginAccount =[Select Id, password__c, email__c From Account Where email__c=: userName ];
} catch (Exception e) {
throw new RemoteVFException('qualcosa di innateso è successo');
}
if(loginAccount.size()==1){
userId=loginAccount.get(0).id;
} else if(loginAccount.size()==0) {
throw new RemoteVFException('nome o password non corretti');
} else{
throw new RemoteVFException('qualcosa di innateso è successo');
}
return new PageReference('/TR/InsertTr?uid=' + UserId);
}
Best Answer
Your issue is because jQuery is not accessible to your Site user and all of the script in the page requires jQuery.
The error shown in the browser is:
To resolve it, change the
Cache Control
setting on theStatic Resource
namedMobileSample_Resources_jQueryMobile
toPublic
. This will allow the Static Resource to be publicly visible.