kindly let me know how to display records using @remoteAction on vf page. kindly rectify my vf page code.currently its displaying null values.
Thanks.
apex class:-
public class javascriptremoting {
@remoteAction
public static List<Account> loadaccs(){
return [select Id,Name from Account];
}
}
vf page:
<apex:page controller="javascriptremoting" id="pg">
<div id="ot" >
{!names}
</div>
<script>
javascriptremoting.loadaccs(function(result,event){
var names=[];
//var names='';
for(integer i=0;i<=result.length;i++){
names=result[i].Name;
}
document.getElementById('ot').innerHtml=names;
});
</script>
</apex:page>
Best Answer
Here you go: Tried this in my org and it works. Remember this is Javascript so you cannot use the "Integer" keyword in the for loop. Also fixed up the looping mechanism.
Please use better naming conventions. Also review this great answer here on understanding JS remoting. Get List Values in JavaScript Remoting
You are now working on a list of accounts returned and not a single object. Try this.