Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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
Javascript Ajax+js(不带jquery)_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript Ajax+js(不带jquery)

Javascript Ajax+js(不带jquery),javascript,jquery,ajax,Javascript,Jquery,Ajax,我在IE上遇到了一个问题。这个代码在IE中不起作用,但在其他的IE中效果很好。我发现IE不能与jQueryAjax一起工作,所以它需要没有。也许有人知道这件事 $(document).ready(function () { $.ajax({ url: 'http://api.randomuser.me/?results=11', dataType: 'text', success: function (result, textStatus,

我在IE上遇到了一个问题。这个代码在IE中不起作用,但在其他的IE中效果很好。我发现IE不能与jQueryAjax一起工作,所以它需要没有。也许有人知道这件事

$(document).ready(function () {
    $.ajax({
        url: 'http://api.randomuser.me/?results=11',
        dataType: 'text',
        success: function (result, textStatus, XMLHttpRequest) {
            console.log(result);
            //alert(result);
            var event = JSON.parse(result);
            var our_html = "<table 'border='0' cellpadding='0' cellspacing='0'>";
            our_html += "<tr><th style='width:52px;border-left:none;'>№</th><th>Имя Фамилия Отчество</th><th>Адрес</th><th>Фото</th><th style='width:180px;border-right: none;'>Действие</th></tr>";
            event.results.forEach(function (item, item_number) {
                var u = item.user;
                our_html += "<tr>";
                our_html += "<td style='width:52px;'>" + (parseInt(item_number) + 1) + "</td>";
                our_html += "<td class='usname'>" + u.name.title + "." + "<span>" + u.name.first + "</span>" + " " + "<span>" + u.name.last + "</span>" + "</td>";
                our_html += "<td class='usst'>" + "<span>" + u.location.city + "</span>" + ", " + u.location.street + "</td>";

                our_html += '<td style="width:146px;"><img style="max-width:60px; max-height:60px;border-radius: 30px;" src="' + u.picture.medium + '"></td>';
                our_html += '<td style="width:180px; border-right: solid 1px #e1e1e1;"><div class="more" onclick="alert("' + u.name.first + '")">Просмотреть</div></td>';
                our_html += "</tr>";
            });
            our_html += "</table>";

            document.getElementById("table-wrapper").innerHTML = our_html;
            //alert (event.results[0].user.name.title);  // Goper
            //$(".simple p").text(event.results[0].user.name.title);
        }
    });
});

因为您已经在使用jQuery,所以应该使用它而不是普通的DOM脚本

而不是

document.getElementById("table-wrapper").innerHTML=our_html;
尝试使用:

$('#table-wrapper').html(our_html);

在这里工作:

这里有一个不带jQuery的支持IE8+的解决方案:

var request = new XMLHttpRequest();
request.open('GET', 'http://api.randomuser.me/?results=11', true);

request.onreadystatechange = function() {
  if (this.readyState === 4) {
    if (this.status >= 200 && this.status < 400) {
      var resp = this.responseText;
      var yourEvent = JSON.parse(resp);
      //Do whatever you want with the yourEvent variable
    } else {
      //Debug error here!
      console.error("An error occurred");
    }
  }
};

request.send();
request = null;

非常感谢,

jQuery AJAX在IE中运行良好。您遇到了什么问题?什么版本的jQuery和IE?没有jQuery和$document.readyfunction{$.ajax{?什么版本的IE?6和11处理起来有点不同。jQuery AJAX在IE中工作得很好。您使用的IE和jQuery版本是什么?jQuery 2.0+删除了对旧IE浏览器的支持,所以您可能需要降级到1.11。我有IE 11。所以它不起作用。我尝试了不同的jQuery版本。1.8-2.2。这段代码不起作用在IE中,我以前看到过。尝试了很多次,真的。你能给我看一下TeamViewer吗?Mbe我做了一些错误的事情,它在IE中不起作用。在其他情况下是好的,在IE控制台SCRIPT5009:JSON undefinedOh中,这是一个已知的问题。你可以用这个库替换JSON.parse:哪一个?只有JSON.js?谢谢你这么多人!你真的帮助了我在.Broo编写你的wmz,我会给你一些,因为你使用的是IE11,我刚刚测试过。正如你所看到的,它在IE11:ths中工作。所以我的代码很好?真的吗?只是把$'table-wrapper'.htmlour\u html;放在我的代码里?有趣的是…它不是那样工作的…我在开放服务器上,本地服务器上工作。所以,我有一个页面,它不工作..Url那个你给我看,它不是那样工作的是的,你试过吗?是的,我试过。所以如果我给你看skype,你会明白我的意思,你能给skype吗?我的svitoi41