ajax asmx 404,ajax webservice asmx 401未经授权的错误(ajax webservice asmx 401 unauthorized error)…

ajax asmx 404,ajax webservice asmx 401未经授权的错误(ajax webservice asmx 401 unauthorized error)…ajaxwebserviceasmx401未经授权的错误(ajaxwebserviceasmx401unauthorizederror)我有一个内部网站,需要登录才能让人们在会议期间记录笔记和其他信息。我试图通过AJAX调用将数据发布到同一服务器上的Web服务,在同一文件夹中。我收到401未经授权的错误。使用Javascript:functionsaveNotes(){var…

大家好,又见面了,我是你们的朋友全栈君。

ajax webservice asmx 401未经授权的错误(ajax webservice asmx 401 unauthorized error)

我有一个内部网站,需要登录才能让人们在会议期间记录笔记和其他信息。 我试图通过AJAX调用将数据发布到同一服务器上的Web服务,在同一文件夹中。 我收到401未经授权的错误。

使用Javascript:

function saveNotes()

{

var json = “{ ID: 5, Note: ‘Test Note’}”;

$.ajax({

type: “POST”,

url: “AutoSaveService.asmx/AutoSave”,

data: json,

xhrFields: { withCredentials: true },

contentType: “application/json; charset=utf-8”,

dataType: “json”,

success: function (r) {

var data = JSON.parse(r.d);

console.log(data.M + “:” + data.N)

},

error: function (r) { console.log(r.responseText); },

failure: function (r) { console.log(r.responseText); }

});

}

WebService asmx文件:

[System.Web.Services.WebService(Namespace = “http://tempuri.org/”)]

[System.Web.Services.WebServiceBinding(ConformsTo = System.Web.Services.WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

public class AutoSaveService : System.Web.Services.WebService

{

[System.Web.Services.WebMethod]

[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]

public static string AutoSave(int ID, string Note)

{

var data = new { M = ID, N = Note };

System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();

return js.Serialize(data);

}

}

我正在使用表单身份验证(身份验证与AD):

我以前从未在安全环境中进行过Ajax调用,请告诉我您需要的其他信息。

我研究过类似问题的其他解决方案,但无法让他们工作。

I have an internal website that requires a login where people can record notes and other information during meetings. I am trying to post the data with an AJAX call to a webservice on the same server, in the same folder. I am getting an 401 unauthorized error.

Javascript:

function saveNotes()

{

var json = “{ ID: 5, Note: ‘Test Note’}”;

$.ajax({

type: “POST”,

url: “AutoSaveService.asmx/AutoSave”,

data: json,

xhrFields: { withCredentials: true },

contentType: “application/json; charset=utf-8”,

dataType: “json”,

success: function (r) {

var data = JSON.parse(r.d);

console.log(data.M + “:” + data.N)

},

error: function (r) { console.log(r.responseText); },

failure: function (r) { console.log(r.responseText); }

});

}

WebService asmx file:

[System.Web.Services.WebService(Namespace = “http://tempuri.org/”)]

[System.Web.Services.WebServiceBinding(ConformsTo = System.Web.Services.WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]

public class AutoSaveService : System.Web.Services.WebService

{

[System.Web.Services.WebMethod]

[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]

public static string AutoSave(int ID, string Note)

{

var data = new { M = ID, N = Note };

System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();

return js.Serialize(data);

}

}

I am using forms authentication (authenticating vs AD):

I have never done ajax calls within a secure environment before, let me know what other information you need.

I’ve looked at other solutions to similar problems but can’t get them to work.

原文:https://stackoverflow.com/questions/40142054

更新时间:2020-05-28 16:05

最满意答案

我想到了。

public static string AutoSave(int ID, string Note)

应该:

public string AutoSave(int ID, string Note)

I figured it out.

public static string AutoSave(int ID, string Note)

should be:

public string AutoSave(int ID, string Note)

相关问答

1)当我尝试测试你的web服务时,它告诉我: “测试表单只适用于来自本地机器的请求” 警告:完成测试后,请勿将此web.config保存为这样 将其添加到web.config中,以便您可以测试localhost之外的webservice:

您可以尝试使用以下链接中描述的方法。 http://www.mindfiresolutions.com/ColdfusionMaking-a-call-to-a-Web-Service-with-complex-object-as-input-parameter-1228.php You can try with the method described in the below link. http://www.mindfiresolutions.com/ColdfusionMaking-a-c

不能 s.ADD(12,34);

textBox1.Text = s.ToString();

是 textbox1.Text = s.ADD(12, 34).ToString(); ? Shouldn’t s.ADD(12,34);

textBox1.Text = s.ToString();

be textbox1.Text = s.ADD(12, 34).ToString(); ?

您只传递对象的属性,而不是整个对象容器。 所以,web方法期待这样的事情: {returnHeader:{“ID”:-1,”OrderHeaderID”:5,”StatusID”:1,”DeliveryCharge”:0,”CreatedBy”:”77777777″,”ApprovedBy”:”77777777″}}

You’re only passing in the object’s properties, not the entire object container. So, the w

试着改变 data: ‘{“country”:”‘ + country + ‘”,”city”:”‘ + city + ‘”}’ 至 data: “country=”+country+”&city=”+city Try to change data: ‘{“country”:”‘ + country + ‘”,”city”:”‘ + city + ‘”}’ To data: “country=”+country+”&city=”+city

我想到了。 public static string AutoSave(int ID, string Note)

应该: public string AutoSave(int ID, string Note)

I figured it out. public static string AutoSave(int ID, string Note)

should be: public string AutoSave(int ID, string Note)

我可以想到两个选择: 1)在AJAX调用中使用POST而不是GET: type: “POST”,

或2)如果您必须使用GET,请配置您的Web服务方法以允许GETS: [WebMethod]

[ScriptMethod(UseHttpGet = true)]

public List gettutors(string data)

{

var tutorManager = new TutorManager();

return tutorManager.GetTutorA

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/132226.html原文链接:https://javaforall.net

(0)
上一篇 2022年4月30日 下午4:20
下一篇 2022年4月30日 下午4:20


相关推荐

  • Spring 常用注解

    Spring 常用注解Spring 常用注解 Component 任何层 Controller Service Repository dao 用于实例化对象 Autowired 对象属性的依赖注入 Qualifier 要和 Autowired 联合使用 代表在按照类型匹配的基础上 再按照名称匹配 Resource 按照属性名称依赖注入 ComponentSca 组件扫描 Configuratio 被此注解标注的类 会被 Spring 认为是配置类 Spring 在启动的时候会自动扫描并加载所有配置类

    2026年3月16日
    1
  • Matlab绘图-很详细,很全面

    Matlab绘图-很详细,很全面

    Matlab绘图
    强大的绘图功能是Matlab的特点之一,Matlab提供了一系列的绘图函数,用户不需要过多的考虑绘图的细节,只需要给出一些基本参数就能得到所需图形,这类函数称为高层绘图函数。此外,Matlab还提供了直接对图形句柄进行操作的低层绘图操作。这类操作将图形的每个图形元素(如坐标轴、曲线、文字等)看做一个独立的对象,系统给每个对象分配一个句柄,可以通过句柄对该图形元素进行操作,而不影响其他部分。
    本章介绍绘制二维和三维图形的高层绘图函数以及其他图形控制

    2022年5月31日
    39
  • 踩坑记录:springboot 不识别properties配置文件

    踩坑记录:springboot 不识别properties配置文件

    2020年11月19日
    268
  • 【pandas】[3] DataFrame 数据合并,连接(merge,join,concat)

    【pandas】[3] DataFrame 数据合并,连接(merge,join,concat)作者 lianghc 连接 http blog csdn net zutsoft article details merge nbsp 通过键拼接列 pandas 提供了一个类似于关系数据库的连接 join 操作的方法 merage 可以根据一个或多个键将不同 DataFrame 中的行连接起来语法如下 merge left right how inner on No

    2026年3月16日
    2
  • ConcurrentHashMap 1.7和1.8区别

    ConcurrentHashMap 1.7和1.8区别ConcurrentHashMap与HashMap和Hashtable最大的不同在于:put和get两次Hash到达指定的HashEntry,第一次hash到达Segment,第二次到达Segment里面的Entry,然后在遍历entry链表(1)从1.7到1.8版本,由于HashEntry从链表变成了红黑树所以concurrentHashMap的时间复杂度从O(n)到O…

    2022年6月24日
    30
  • 什么是列式存储数据库?

    什么是列式存储数据库?列存储不同于传统的关系型数据库 其数据在表中是按行存储的 列方式所带来的重要好处之一就是 由于查询中的选择规则是通过列来定义的 因此整个数据库是自动索引化的 按列存储每个字段的数据聚集存储 在查询只需要少数几个字段的时候 能大大减少读取的数据量 一个字段的数据聚集存储 那就更容易为这种聚集存储设计更好的压缩 解压算法 传统的行存储和列存储的区别 nbsp 1 数据是按行存储的 nbsp 2 没有索引的查询使用大量 I

    2026年3月26日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号