简体   繁体   English

Salesforce使用Jquery将数据从visualforce页面发送到apex控制器

[英]Salesforce Send data from visualforce page to apex controller with Jquery

I am new to Salesforce and have a question on VisualForce pages (VF) and Apex Controllers. 我是Salesforce的新手,对VisualForce页面(VF)和Apex控制器有疑问。

If i have a VF page with a controller included in it, then when the page loads, a new instance of the controller will be created on SFDC. 如果我有一个包含控制器的VF页面,则在加载该页面时,将在SFDC上创建该控制器的新实例。 Is this correct? 这个对吗?

if correct, then the Controller will have some state having some variables which holds some data. 如果正确,则控制器将具有一些状态,该状态包含一些变量,这些变量保存一些数据。 If i want to access a VF page which also had the same controller included in tag, then will that VF page can access the same info of the same controller instance or will that create a new instance of that controller ? 如果我想访问在标签中也包含相同控制器的VF页面,那么该VF页面可以访问相同控制器实例的相同信息还是创建该控制器的新实例?

I came to know that using can be used to make ajax calls to the controller which sends the view state from client and updates the viewstate when response comes to browser. 我知道使用using可以对控制器进行ajax调用,该控制器从客户端发送视图状态并在响应浏览器时更新视图状态。 But, Salesforce(SFDC) sends lots of junk when i use . 但是,当我使用Salesforce(SFDC)时会发送很多垃圾。 I don't want all this junk. 我不要所有这些垃圾。 i just need to send a small JSON string from controller. 我只需要从控制器发送一个小的JSON字符串。

I am trying to use the JQuery AJAX call to some VF page which is also having the same controller included. 我正在尝试对某些VF页面使用JQuery AJAX调用,该页面也包含相同的控制器。 My doubt is whether it uses the same instance of that controller or will that create a new instance? 我的疑问是它是否使用该控制器的相同实例,还是将创建一个新实例?

you can use RemoteAction 您可以使用RemoteAction

global with sharing class myController{
    @RemoteAction
    global static string foo(String str) {
        return 'OK';
    }
}

On Page 在页面上

<script>
myController.foo('str',callBack)

function callBack(res){
  alert(res);
}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM