jQuery Ajax转到空白页 [英] jquery Ajax goes to a blank page

查看:209
本文介绍了jQuery Ajax转到空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jquery功能强大,但存在许多不同的问题. 我有这个代码:

jquery is powerful but has a many different problems. i have this code:

 $(
     function () {
         // Get a reference to the content div (into which we will load content).
         var jContent = $("#content");

         // Hook up link click events to load content.
         $("ul li a").click(
             function () {
                 var jLink = $(this);

                 // Clear status list.
                 $("#ajax-status").empty();

                 // Launch AJAX request.
                 $.ajax({
                     // The link we are accessing.
                     url: jLink.attr("href"),

                     // The type of request.
                     type: "GET",

                     // The type of data that is getting returned.
                     dataType: "html",


                     error: function () {
                         ShowStatus("AJAX - error()");

                         // Load the content in to the page.
                         jContent.html("<p>Page Not Found!!</p>");
                     },

                     beforeSend: function () {
                         ShowStatus("AJAX - beforeSend()");
                     },

                     complete: function () {
                         ShowStatus("AJAX - complete()");
                     },

                     success: function (strData) {
                         ShowStatus("AJAX - success()");
                         jContent.html($(strData).find('#bglogin').html());
                     }
                 });

                 // Prevent default click.
                 return (false);
             }
         );

     }
 );

当我在博客上使用它时,它会转到空白白页.我更改了很多次,但是它不起作用.但是,当我在空白页面上使用它时(仅将此代码用于博客),它可以工作并且是一个新问题. 我们在此页面中认为:/login 有以下标签:

when i use it on my blog it goes to a blank white page. i change it many times, but it does not work. but, when i use it on a blank page, (use this code only for blog) it works and a new problem. we think in this page: /login there are these tags:

<div id="login">
   <div id="bglogin">
     <p>hello</p>
   </div>
</div>

当我调用获取#bglogin id的jQuery (jContent.html($( strData ).find('#bglogin').html());)时,它获取代码,但是,当我想要#login id时, 它什么也没给我.

when i call the jquery (jContent.html($( strData ).find('#bglogin').html());) that get #bglogin id, it get the code, but, when i want the #login id, it doesn't get me anything.

推荐答案

使用此html:

<div id="login">
   <div id="bglogin">
     <p>hello</p>
   </div>
</div>

此javascript

This javascript

$(strData).find('#login').html()

不提供任何内容,因为find方法会查找子元素,并且在这种情况下,您的根元素是#login.您正在从#login元素中查找ID为#loginchild,代码无法找到它.这就是为什么它不起作用.在这种情况下,只需写:

does not give you anything because the find method looks for the child elements and your root element in this case is #login. You're looking for a child with id #login from the #login element, the code cannot find it. That's why it does not work. In this case, just simply write:

jContent.html(strData);

这篇关于jQuery Ajax转到空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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