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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • fmp helper下载_sftp下载

    fmp helper下载_sftp下载1.下载安装https://teleport-pro.en.softonic.com/或者其他激活成功教程网站2.运行扒站打开软件后File->NewProjectWizard里面可以选择许多TP能做的事情,比如创建一个网站的副本,根据关键词查询网站等。下载网站选择第一个。输入想要下载的网址,和对应的下载深度。选择仅下载文本或是全部。其次如果该网站需要登陆的话需要输入登陆网…

    2022年9月8日
    1
  • windows XP虚拟机安装[通俗易懂]

    windows XP虚拟机安装[通俗易懂]一.安装环境:win10VMware15winxp.iso二.安装过程:1.用自定义(高级)安装(原因是虚拟磁盘类型必须选IDE,而典型是默认磁盘类型的,如果你用典型发现到后面会报错)2.按照自己的需求选择硬件兼容性,建议选择最高的,因为向下兼容。3.插入.iso文件4.选择操作系统和版本5.修改名称和选择安装位置(可默认)6.根据自己的需求修改处理器配置,内存(不得低于1G,即1024MB)、网络类型、I/O控制类型。7.磁盘类型是重点,一定要选择IDE。8.磁盘。

    2022年8月16日
    6
  • 代码主题darcula_darcula主题模式是()模式。_学小易找答案

    代码主题darcula_darcula主题模式是()模式。_学小易找答案【多选题】androidstudio安装并配置完成后,在命令行窗口输入()命令验证配置成功。【填空题】darcula主题模式是()模式。【单选题】当前unity官网最新版本是()【多选题】如何将制表位删除()【单选题】B大调的谱号为:【判断题】受拉的杆件可以简化为一个点,因为除了端头以外,其它任何位置的一点的力学行为都是相同的。【单选题】Android是一种基于()的自由及开放源代码的…

    2022年6月27日
    28
  • datax(7):JobContainer源码解读

    datax(7):JobContainer源码解读前面已经看了Engine,其中有一步就是判断container是job还是taskGroup类型。本文就好好看看JobContainer。一,概述JobContainer:job实例运行在jobContainer容器中,它是所有任务的master,负责初始化、拆分、调度、运行、回收、监控和汇报,但它并不做实际的数据同步操作1、如果是job类型,则依次执行job的preHandler()、init()、prepare()、split()、schedule()、-post()、post.

    2022年5月16日
    43
  • android activity singletask,Android Activity启动模式之singleTask实例详解

    android activity singletask,Android Activity启动模式之singleTask实例详解本文实例分析了AndroidActivity启动模式之singleTask。分享给大家供大家参考,具体如下:前面的文章介绍了Android活动Activity的启动模式:standard和singleTop。本文继续介绍Activity的下一个启动模式:singleTask。singleTask:当设置活动的启动模式为singleTask时,首先检查返回栈中是否存在当前活动,如果存在当前活…

    2022年6月26日
    30
  • checkstyle使用_idea checkstyle

    checkstyle使用_idea checkstyleCheckstyle是一款检查java程序代码样式的工具,可以有效的帮助我们检视代码以便更好的遵循代码编写标准,特别适用于小组开发时彼此间的样式规范和统一。Checkstyle提供了高可配置性,以便适

    2022年8月4日
    6

发表回复

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

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