[英]XMLHTTPRequest, C# calling a single method in the code behind?
我将xhr用于文件上传器,以打开我拥有的连接:
xhr.open('POST','ProgressTest.aspx / UploadFile',true);
但是,这在我调试时不会命中UploadFile方法,它总是会在ProgressTest.aspx中命中Page_Load,这不是我想要的。 我有[WebMethod]赋予的UploadFile。 我在这里缺少什么吗?
为了使ASP.NET调用Web方法,请求的Content-Type必须为'application / json'。 以下javascript代码应该可以解决您的问题:
var xhr = new XMLHttpRequest();
xhr.open('POST', 'ProgressTest.aspx/UploadFile', true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
xhr.send();
另外,请确保将C#方法设为静态,否则ASP.NET将无法找到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.