如何使用 JavaScript 或 Jquery 动态更改 HTML 文本输入
我有一个返回字符串的网络服务。 https://localhost:5001/mywebservice
现在,我制作了一个带有文本输入的 HTML 页面。 我想使用 JavaScript 或 JQuery 来调用我的网络服务。 然后用我的网络服务返回的任何内容更新文本输入 https://localhost:5001/mywebservice
我尝试使用以下 JQuery 代码片段。 但这行不通。
$('button').on('click', function (e) {
var str = $('https://localhost:5001/mywebservice').val();
$("#MyString").prop('value', str);
});
如果有人能给我提示,我将不胜感激。 感谢您的帮助。
I have a web service that returns a string.
https://localhost:5001/mywebservice
Now, I made a HTML page with a text input.
I'd like to use to JavaScript or JQuery to call my webservice.
Then update the text input with whatever returns from my web service
https://localhost:5001/mywebservice
I tried to use the following JQuery code snippet.
But it won't work.
$('button').on('click', function (e) {
var str = $('https://localhost:5001/mywebservice').val();
$("#MyString").prop('value', str);
});
I'd appreciate it if someone can give me a hint.
Thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,首先,您正确地完成了事件侦听器。
如果此脚本在 HTML 文件中运行,则您可以从文档中选择元素。 。
如果它是文本框,则使用;如果它是元素,则使用
.html()
要请求您的服务的返回信息,请勿使用 jquery $。它不是为 ajax 构建的。
ok, so first of all, you did the event listener right.
If this script runs within the HTML file, then you can select elements from the document. Use
if it is a text box or
.html()
if it is an element.To request the return info of your service, do not use jquery $. it was not built to ajax.