Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQUERY AJAX-如何将凭据(用户和密码)传递到Sharepoint Webservice_Jquery_Web Services_Internet Explorer_Sharepoint_Firefox Addon - Fatal编程技术网

JQUERY AJAX-如何将凭据(用户和密码)传递到Sharepoint Webservice

JQUERY AJAX-如何将凭据(用户和密码)传递到Sharepoint Webservice,jquery,web-services,internet-explorer,sharepoint,firefox-addon,Jquery,Web Services,Internet Explorer,Sharepoint,Firefox Addon,当我使用Internet Explorer调用任何Sharepoint Web服务时,浏览器会要求我提供凭据。。。但当我使用Firefox或Chrome时,会出现“401未经授权”错误 我正在编写一个Firefox扩展,所以我需要知道如何使用JQuery传递凭据 $.ajax({ url: "http://sharepoint.xxxx.com/_vti_bin/search.asmx", type: "POST", dataType: "xml", data

当我使用Internet Explorer调用任何Sharepoint Web服务时,浏览器会要求我提供凭据。。。但当我使用Firefox或Chrome时,会出现“401未经授权”错误

我正在编写一个Firefox扩展,所以我需要知道如何使用JQuery传递凭据

 $.ajax({
    url: "http://sharepoint.xxxx.com/_vti_bin/search.asmx", 
    type: "POST",
    dataType: "xml",
    data: soapEnv,
    complete: processResult,
    contentType: "text/xml; charset=utf-8"
}); 

    $.ajax({
        url: "http://sharepoint.xxxx.com/_vti_bin/lists.asmx",
        beforeSend: function(xhr) {
            xhr.setRequestHeader("SOAPAction",
            "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
        },
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=utf-8"
    });

您应该能够通过以下方式传递用户名/密码:

$.ajax({
    url: "http://sharepoint.xxxx.com/_vti_bin/search.asmx", 
    type: "POST",
    xhrFields: {
        withCredentials: true
    },
    dataType: "xml",
    data: soapEnv,
    complete: processResult,
    contentType: "text/xml; charset=utf-8"
    username: username,
    password: password,
    crossDomain: true
});

通过使用xhrFields
和credentials:true
并传递用户名和密码,您可以在通话的其余部分发送这些项目。另外,请注意,
crossDomain:true
用于告诉jQuery进行任何必要的更改以允许跨域调用。

可能重复您正在进行的跨域查询,这就是原因。Firefox具有安全性,为了使其允许,应在IIS中的服务器上启用跨域设置,在IIS7上启用跨源资源共享。如果要访问来自不同Sharepoint应用程序的列表数据,另一种方法是使用搜索。尝试向参数添加标题,如:标题:{“内容类型”:“文本/普通”,“授权”:“基本”+btoa(“用户名:密码”),},为什么要在JavaScript中传递用户名和密码?关于Vijay的问题,在使用仅AJAX的服务时,可能需要发布用户/密码。显然,除非使用SSL,否则应该避免使用纯文本发布。即使如此,发送浏览器加密/哈希密码以提供另一层安全性也是一个好主意。