[英]How do I connect Azure Httptrigger to website?
I have limited experience with creating websites/front-end - just HTML/CSS - and work mostly on the backend - Node.js in Azure functions. 我在创建网站/前端(仅HTML / CSS)方面经验有限,并且主要在后端(Azure函数中的Node.js)上工作。
I have created an Azure function (httptrigger) that I would like a button on my website to hit. 我已经创建了一个Azure函数(httptrigger),我希望点击我网站上的一个按钮。
For example, like a search bar, I want a user to type something and click search. 例如,像搜索栏一样,我希望用户键入内容并单击搜索。 After they click search I want to hit the http trigger with the search contents in the query string.
在他们单击搜索之后,我想在查询字符串中单击带有搜索内容的http触发器。
After hitting my trigger, I would then want it to return some data to show on the webpage. 按下触发器后,我希望它返回一些数据以显示在网页上。
I am struggling with adding the search content to the query string (and perhaps securely hiding the httptrigger endpoint?) and how I would send data back to the html website. 我正在努力将搜索内容添加到查询字符串中(也许安全地隐藏了httptrigger端点?),以及如何将数据发送回html网站。
At the moment, I have built the httptrigger to work and return html data via context.res= {body: html}
which works fine when I post the httptrigger url into my browser, but of course I want this to send data back and affect the current webpage with the search bar, by adding the results below it. 目前,我已经构建了httptrigger来工作,并通过
context.res= {body: html}
返回html数据,当我将httptrigger url发布到浏览器中时,它可以正常工作,但是我当然希望它将数据发送回去并影响通过将搜索结果添加到当前网页下方的搜索栏。
Any pointers or tips here would be greatly appreciated as I'm not too experienced sewing the front end together with this. 这里的任何指针或技巧都将不胜感激,因为我对将前端与此缝在一起不太有经验。
Thanks! 谢谢!
So my suggestion is to break this down a little bit and possibly create some new more specific questions based on that breakdown. 因此,我的建议是对此进行分解,并可能基于该分解来提出一些新的更具体的问题。 As it is this is pretty broad.
因为这是相当广泛的。
Realize that from your web site's (front end) perspective there isn't anything different about hitting and Azure Function Http Trigger then any other REST endpoint and the answer to how to wire it in on the front end is going to vary greatly based on any frameworks you may be using (sometimes those frameworks even want data returned in a specific way as well). 从网站(前端)的角度认识到,点击和Azure Function Http Trigger并没有什么不同,然后是其他任何REST终结点,并且如何将其连接到前端的答案将基于任何您可能正在使用的框架(有时这些框架甚至还希望以特定方式返回数据)。
With that knowledge in mind I would focus first on ensuring your Azure Function is properly configured and generating a JSON result you expect before trying to work with the UI. 考虑到这些知识,在尝试使用UI之前,我将首先关注确保正确配置Azure函数并生成期望的JSON结果。 I can give you some suggestions in that regard:
在这方面,我可以给您一些建议:
module.exports = function(context, req) { if (req.query.filter) { // Do something with the filter parameter when loading results context.res = { body: '[{"name": "New York","abbreviation": "NY"},{"name": "Ohio","abbreviation": "OH"}]', headers: { 'Content-Type': 'application/json' } }; } else { context.res = { status: 400, body: "Please pass a filter on the query string" }; } context.done(); };
Once you have a working function that returns back your data then move on to tackle your UI integration. 一旦具有可以返回数据的工作功能,然后继续进行UI集成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.