相关疑难解决方法(0)

在跨域调用的IE中,Jquery $ .ajax失败

我正在使用跨域请求$.ajax.它适用于Firefox和Chrome,但不会在IE 7或8上发出呼叫.任何人都可以告诉我以下内容有什么问题吗?

  1. 我使用了JSON和JSONP(由于一些自定义限制,我停止使用它).
  2. 我已经Allow-access-control-origin在我的网站上使用标题了.(没有这些,Chrome和Firefox没有成功请求.)
  3. 我已经尝试过https://developer.mozilla.org/en/http_access_control

码:

$.ajax({
    type: 'GET',
    url: "http://anotherdomain.com/Service/GetControl?id=" + zoneID,
    cache: false,
    contentType: "application/x-www-form-urlencoded",
    async: false,
    beforeSend: function (request) {
        //alert('before send');
        //request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
        //request.setRequestHeader("X-PINGOTHER", "pingpong");
    } ,
    success: function (data, status) {
        //alert("Data returned :" + data);
        //alert("Status :" + status);
        if (status == "success" && data != "")
            $("#" + div.id).append(data);
        else
            $("#" + div.id).attr("style", "display:none;");
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert(textStatus);
        alert(errorThrown);
    }
});
Run Code Online (Sandbox Code Playgroud)

我尝试了多个网站上的各种提示,但还没有运气.

jquery cross-domain

64
推荐指数
6
解决办法
10万
查看次数

IE9,IE8与AngularJS CORS返回"访问被拒绝" - ASP.NET WebApi

在IE8和9中,当我正在进行CORS webapi调用时,我收到以下JavaScript错误:

Error: Access is denied.
{
  [functions]: ,
  description: "Access is denied.",
  message: "Access is denied.",
  name: "Error",
  number: -2147024891
}
Run Code Online (Sandbox Code Playgroud)

我设置了像这里描述的WebApi http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api

所以WebApi包含:

  public static class WebApiConfig
  {
      public static void Register(HttpConfiguration config)
      {
          config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
      [...]
Run Code Online (Sandbox Code Playgroud)

我的测试AngularJS App:

  <!DOCTYPE html>
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ng="http://angularjs.org" ng-app="app">
  <head>
      <title>test</title>
      <script src="Scripts/angular.js"></script>
      <script src="app.js"></script>
  </head>
  <body>
      <div ng-controller="testController as vm">
          {{vm.test}}
          {{vm.data}}
      </div>
  </body>
  </html>
Run Code Online (Sandbox Code Playgroud)

app.js:

  var app = angular.module('app');

  app.controller('testController', function ($http) {
      var vm;
      vm = this; …
Run Code Online (Sandbox Code Playgroud)

javascript c# asp.net-web-api angularjs

6
推荐指数
1
解决办法
6333
查看次数