简体   繁体   English

Ajax调用Web服务-方法成功,但禁止数据访问

[英]Ajax call to web service - success in method but forbids data access

I am trying to call a web service from an ajax jquery. 我正在尝试从ajax jQuery调用Web服务。 It is successfully entering the success method but unfortunately a 403 error is being triggered and thus won't allow me to access the data. 它正在成功输入成功方法,但不幸的是,触发了403错误,因此不允许我访问数据。

This is my code: 这是我的代码:

    try {
    $.ajax({
  type: "POST",
  url: urlAddress,
  data: dataa,
  contentType: "text/xml; charset=utf-8",

  success: function(Msg) {
 //   $("#Result").text(msg.d);
    alert("ok");
    alert("hi "+Msg.responseText + " How are you?");
  },

  error: function(request, status, error) {
      alert("Error "+request.statusText.toString()); 
      alert("ERROR");
  }
});
    }
    catch (e)
    {}

Msg.ResponseText comes back "undefined" Msg.ResponseText返回“未定义”

From Live Http Headers I get the following: 从Live Http标头中,我得到以下信息:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9, / ;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Origin: null Access-Control-Request-Method: POST 接受:text / html,application / xhtml + xml,application / xml; q = 0.9, / ; q = 0.8 Accept-Language:zh-cn,en; q = 0.5 Accept-Encoding:gzip,deflate Accept-Charset:ISO -8859-1,utf-8; q = 0.7,*; q = 0.7 Keep-Alive:115连接:keep-alive来源:null访问控制请求方法:POST

HTTP/1.1 403 Forbidden Content-Length:1758 Content-Type: text/html Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET Date: Tue, 27 Jul 2010 10:59:04 GMT HTTP / 1.1 403禁止的内容长度:1758内容类型:text / html服务器:Microsoft-IIS / 6.0 X-Powered-通过:ASP.NET日期:Tue,27 Jul 2010 10:59:04 GMT

Smells like urlAddress is not located on the same domain you're running that script. 闻起来像urlAddress不在您运行该脚本的同一域上。

That would breach the same origin policy and therefore, fail. 那会违反same origin policy ,因此会失败。

If I'm wrong here with that assumption, your're webservice might require a login (username+password) which you might missing to pass through .ajax() . 如果我对此假设有误,则您的Web服务可能需要登录名(用户名和密码),而您可能无法通过.ajax()进行传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM