无法从javascript调用控制器中的远程方法。
JavaScript代码:
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.FitAssistenceController.updateObesityGoal}',
WeightValue,CaloriesValue,pastGoalRecommendedSteps,walkingSpeed,
function(result, event) {
console.log("event",event);
console.log("result",result);
}
);
远程方法:
@RemoteAction
global static void updateObesityGoal(String weightGoal,String calChange,String RecommendedSteps,String walkingType){
/* perform the action */
}
除了safari之外,这在所有浏览器中都很好用。
客户端错误如下所示:
[Error] XMLHttpRequest cannot load https://fitblissdev17-dev-ed--c.na40.visual.force.com/apexremote due to access control checks.
request (VFRemote.js:42:137)
request (VFRemote.js:74:225)
doSend (VFRemote.js:96)
combineAndSend (VFRemote.js:96:100)
g (VFRemote.js:79:99)
[Error] Visualforce Remoting Exception: Unable to connect to the server (communication failure).
Object
Could not fetch properties. Object may no longer exist.
error (VFRemote.js:117:461)
(anonymous function) (VFRemote.js:134:160)
fire (VFRemote.js:52)
fireEvent (VFRemote.js:47:170)
onProviderData (VFRemote.js:86:195)
fire (VFRemote.js:52)
fireEvent (VFRemote.js:47:170)
onData (VFRemote.js:94:464)
handleFailure (VFRemote.js:75:380)
a (VFRemote.js:39:392)
(anonymous function) (VFRemote.js:40:309)
答案 0 :(得分:1)
我猜你是在按一下按钮调用JavaScript函数吗?
如果是这样,我会尝试使用真正的按钮:
<button type="button" onclick="remoteCall();">Click Me!</button>