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
最满意答案
问题是我正在使用官方文档推荐的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共享appFolder(OneDrive shared appFolder)[2023-06-11]
与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.
-
如何使用Patch-Request重命名OneDrive上的文件/文件夹?(How to rename a file/folder on OneDrive using Patch-Request?)[2023-10-08]
它看起来不像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 ... -
Cloudrail - OneDrive API:高级搜索请求失败(Cloudrail - OneDrive API : Advanced search request fails)[2021-10-22]
微软最近推出了他们新的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- ...