首页 \ 问答 \ Ajax请求控制器(Ajax request to controller)

Ajax请求控制器(Ajax request to controller)

我是Play的新手,用AJAX尝试一些非常简单的东西。 现在我只想将一些数据发送到我的控制器并发回一些东西。 我不知道如何在Play中实现这一点。

我以前用来发送数据

$.get(url, {data:'input'), function() { do something });

到/ url找到的标准servlet。 在servlet中我有一个简单的

out.println("html output")

如果我想在我的html文件中打印一些东西。 我希望你明白这一点。

在Play中我在我的控制器中有一个功能(这是废话,只是一个测试...)

public static void doIt(String input) {
    String out = input+"_foo";
    render(out);
}

我尝试用这样的JQuery / AJAX调用这个函数:

$(document).ready(function() {
      // when I click a button ...
      $("#send").click(function(){
            var url = #{jsAction @doIt(':input') /}     
            $.get(url({input: 'x'}), function() {
                ...
            });
      });
});

这是从教程中获取的,不起作用。 有人可以给我一个想法,如何编写控制器和JS发送一些随机字符串到我的控制器并返回一些东西。

干杯


I'm new to Play and try some very simple things with AJAX. Right now I only want to send some data to my controller and send something back. I don't get how I can realize this in Play.

I used to send data with

$.get(url, {data:'input'), function() { do something });

to a standard servlet found at /url. In the servlet I have a simple

out.println("html output")

if I want to print something in my html file. I hope you get the point.

In Play I have a function in my controller (it's nonsense, just a test...)

public static void doIt(String input) {
    String out = input+"_foo";
    render(out);
}

I try to call this function with JQuery/AJAX like this:

$(document).ready(function() {
      // when I click a button ...
      $("#send").click(function(){
            var url = #{jsAction @doIt(':input') /}     
            $.get(url({input: 'x'}), function() {
                ...
            });
      });
});

This is taken from the tutorial and doesn't work. Can somebody give me an idea how to write the controller and the JS to send some random string to my controller and return something.

Cheers


原文:https://stackoverflow.com/questions/5332587
更新时间:2021-09-19 11:09

最满意答案

问题是我正在使用官方文档推荐的phuague / oauth2软件包。 链接到令牌和授权URL不是v2.0端点。


Problem was that I was using thephpleague/oauth2 package that is recommended by official docs. Links to token and authorize URL were not to the v2.0 endpoint.

相关问答

更多
  • 该应用程序使用的是仅限App的授权 ,目前不支持通过Microsoft Graph API访问OneDrive for Business。 请使用图表资源管理器使用的委托流程 。 The application is using App-only authorization which is currently not supported for accessing OneDrive for Business through Microsoft Graph API. Please use delegated ...
  • 订阅适用于项目,因此您需要: https://{tenant}-my.sharepoint.com/_api/v2.0/drive/root/subscriptions 这方面的文件似乎有点模棱两可。 Subscriptions are applied to items, so you'll want: https://{tenant}-my.sharepoint.com/_api/v2.0/drive/root/subscriptions The docs seem a little ambiguou ...
  • 与OneDrive API的所有连接均通过https加密通道进行。 App方面围绕您用于与OneDrive服务通信的应用程序ID构建,您可以在Android / iOS应用程序上拥有两个单独的应用程序,其中一个免费,一个付费使用相同的底层应用程序ID。 All connections to the OneDrive API are via https encrypted channels. The App aspect is build around the application id that you ...
  • allservices API仅供参考,也就是说您作为人类开发人员查看您可以粗略得到的内容。 为了消除学习路径中的任何障碍,我们已将其设为匿名,以便您立即浏览浏览器。 缺点是如果没有真正的OAuth令牌,服务就无法确定确切的端点URI和资源URI(至少在所有情况下都是如此)。这就是为什么我们决定通过serviceEndpointUri属性,但我们不能想到其他任何有用的东西,我们可以以resourceUri返回。 这就是为什么它是空的。 services是真正的API。 这就是你的应用会击中的。 一旦您熟悉获 ...
  • 噢,我明白了。 我不明白一切,但这里是件。 希望有人会觉得它有用。 答案是, 您可以使用Graph API访问OneDrive / Sharepoint驱动器。 就我而言,问题在于我试图访问的驱动器不是我的驱动器,而是与其他帐户绑定。 我可能有一些非特权帐户。 最后,查询这个URL可以正常工作(在标头中正确设置了承载访问令牌) https://graph.microsoft.com/v1.0/users/itsupport@company.com/drive/root:/RootFolderName:/ch ...
  • 看起来我们在这里有一个错误,我们不尊重该场景中的@name.conflictBehavior注释。 我们正在努力修复。 Looks like we have a bug here where we don't honor the @name.conflictBehavior annotation in that scenario. We're working on a fix.
  • 问题是我正在使用官方文档推荐的phuague / oauth2软件包。 链接到令牌和授权URL不是v2.0端点。 Problem was that I was using thephpleague/oauth2 package that is recommended by official docs. Links to token and authorize URL were not to the v2.0 endpoint.
  • 它看起来不像WebClient可以支持PATCH请求。 您可能需要使用支持其他动词的HttpWebRequest方法( https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.method.aspx )。 http://dev.onedrive.com上的控制台应该可以让您更好地了解如何将请求组合在一起以进行不同的调用。 It doesn't look like WebClient can support PATCH reques ...
  • 微软最近推出了他们新的Graph API,据我所知,所有服务都使用它。 因此,您所指的文档适用于新API。 请尝试使用'/ drive / items / {the_folder_id或root} /view.search?q=txt'。 您还可能需要对参数进行url编码。 所以最安全的解决方案可能就是这样: const url = "/drive/items/root/view.search?q=" + encodeURIComponent("[search query]"); const req = n ...
  • 同步需要几个不同的步骤,OneDrive API中的一些将帮助您,其中一些您将不得不自己做。 变更检测 显然,第一阶段是检测是否有任何变化。 OneDrive API提供了两种机制来检测服务中的更改: 可以使用带有If-None-Match的标准请求检测单个文件的更改: await this.userDrive.Drive.Special.AppRoot.ItemWithPath(remotePath).Content.Request(new Option[] { new HeaderOption("If- ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)