I know about how to pass data between javascript and c# by ajax, and now I want to know fetch.
c#:
namespace WebApplication1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
//[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
javascript:
fetch('http://localhost:62177/WebService1.asmx/HelloWorld')
.then(response => {
alert(response.json());
})
.then(response => {
alert(response);
})
it showed:
The usage of this url is based on ajax.
I changed the url to "http://localhost:62177/WebService1.asmx?op=HelloWorld", it showed:
I thought it was response success, however I received nothing and it showed:
Then I modified the method of return data, now it was json-format :
c#:
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public void HelloWorld()
{
object JSONObj = JsonConvert.SerializeObject("Hello World");
Context.Response.Write(JSONObj);
}
But there was no change.
I don't know how else to change it. Can someone give me a little help?





how to pass data between javascript and c# by ajax... does your "ajax" code use JSON? I mean, the server side code in theajaxmethod that you say you know, is the same regardless, right. So, does your "ajax" method use JSON.parse?System.Web.Services.WebServicestates, "[d]efines the optional base class for XML Web services". XML is not JSON. Use the Network tab in Developer Tools to look at the raw response and see what is being returned.