首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery .ajax错误处理

jQuery .ajax错误处理
EN

Stack Overflow用户
提问于 2015-05-17 00:29:17
回答 1查看 474关注 0票数 0

我尝试使用jQuery.ajax()从table_snippet.html中检索html代码片段,然后替换html代码中的元素。正在执行jQuery.ajax()中的错误处理程序,而不是所需的成功处理程序。

代码语言:javascript
复制
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <title>Table</title>
        <link href="address-data-file.css" type="text/css" rel="stylesheet">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script src="ajax_goodness.js" type="text/javascript"></script> 
    </head>
    <body onload="func()">
        <div id="div_id">
            <p>Use AJAX to retrieve the file table-snippet.html and then replace the div with the contents of that file.</p>
        </div>
    </body>
</html>
代码语言:javascript
复制
function func(){
    jQuery.ajax({
        type: "GET",
        url: "table_snippet.html",
        dataType: "html",
        success: function(data){
            $("#div_id").html(data);
        },
        error: function(){
            alert("fail");
        }
    });
}
EN

回答 1

Stack Overflow用户

发布于 2015-05-17 00:49:01

代码语言:javascript
复制
$(function () {
    $.ajax({url:"table_snippet.html",success:function(result){
      $("#div_id").html(result);
    }});
});
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30278091

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档