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.
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
$("<select your input>").val()
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.
$.ajax({
url:"https://localhost:5001/mywebservice",
success:function(d){
//d is your data
}
})