使用jQuery为AJAX Webservice调用提供代理凭据 [英] Providing proxy credentials for AJAX Webservice call using jQuery

查看:59
本文介绍了使用jQuery为AJAX Webservice调用提供代理凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在办公室实现了代理,我需要使用jQuery AJAX进行webservice调用。



如果我们跳过代理,调用web方法时没有任何错误。

但是当我们启用代理时,我们得到NetworkError没有关于此错误的详细信息。



我们不能永远禁用代理,现在我们想用jQuery AJAX调用这个web服务。

请帮我解决这个问题。



  var  surl =   http://www.mydomain.com/MyJSONService/Service.asmx/HelloWorld; 
$ .ajax({
type:' GET'
url:surl,
crossDomain: true
contentType: application / json; charset = utf-8
dataType: json
xhrFields:{
withCredentials: true
},
成功: function (data,statusCode,xhr){
alert(data.d);
},
错误: function (xhr,status,error){
alert(' 错误!!');
},
async: false
cache: false
});

解决方案

.ajax({
type:' GET'
url: surl,
crossDomain: true
contentType: 应用/ JSON; charset = utf-8
dataType: json
xhrFields:{
withCredentials: true
},
成功: function (data,statusCode,xhr){
alert(data.d);
},
错误: function (xhr,status,error){
alert(' Error !!');
},
async: false
cache: false
});


请尝试如下。



注意: 这只是一个示例。根据您的应用调整它。



 


.ajaxPrefilter(function(options){
if(options.crossDomain){
var newData = {};
//复制选项.data对象到newData.data属性。
//我们需要这样做,因为javascript默认情况下不会深层复制变量。
newData.data =


We have proxy implemented in our office, I need to make webservice call using jQuery AJAX.

If we skip proxy, the web method gets called without any errors.
But the moment we enable proxy, we get "NetworkError" no more details available regarding this error.

We cannot disable proxy forever, now we want to call this webservice using jQuery AJAX.
Please help me resolve the issue.

var surl = "http://www.mydomain.com/MyJSONService/Service.asmx/HelloWorld";
$.ajax({
    type: 'GET',
    url: surl,
    crossDomain: true,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    xhrFields: {
         withCredentials: true
    },
    success: function(data, statusCode, xhr) {
        alert(data.d);
    },
    error: function(xhr, status, error) { 
        alert('Error !!'); 
    },
    async: false,
    cache: false
});

解决方案

.ajax({ type: 'GET', url: surl, crossDomain: true, contentType: "application/json; charset=utf-8", dataType: "json", xhrFields: { withCredentials: true }, success: function(data, statusCode, xhr) { alert(data.d); }, error: function(xhr, status, error) { alert('Error !!'); }, async: false, cache: false });


Please try is as below.

Note: This is just a sample.Adjust it according to your app.


.ajaxPrefilter( function( options ) { if ( options.crossDomain ) { var newData = {}; // Copy the options.data object to the newData.data property. // We need to do this because javascript doesn't deep-copy variables by default. newData.data =


这篇关于使用jQuery为AJAX Webservice调用提供代理凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆