English 中文(简体)
神秘的换行符被附加到ajax加载的内容中
原标题:Mysterious line break is being appended to ajax loaded content
  • 时间:2011-02-11 16:35:27
  •  标签:
  • jquery
  • ajax

Using either .ajax or .load, I m loading content from an .html page into or replace an element. In either case, the content is called and inserted and there is a mysterious new line (not a break element , but like a or ) appended after my content from the .html file.

在chrome的元素检查器中,它看起来像:

<div class="loaded parent">
 // all my loaded content
</div>
"
(ghost line)
"

代码中没有中断,所以我不知道这是从哪里来的。

.html文件:

<div id="ForgotPasswordForm" class="ajax">
 <h2>Reset Your Password test</h2>
 <div class="BlockContent">
 <p> Enter your email below to request a password reset. An email will be send with a reset link. </p>
 <p class="ErrorMessage" style="display:none"></p>
 <form action="/login.php?action=send_password_email" method="post" onsubmit="return check_forgot_password_form()">
 <div>
 <dl style="width: 270px;margin: 0 auto;height: 30px;">
 <dt style="float: left;width: 100px;text-align: right;margin:5px 5px 0 0;"> <span class="Required">*</span> Email Address: </dt>
 <dd style="float:left;font-size:12px;width:150px;">
 <input style="padding:4px;" type="text" class="Textbox" name="email" id="email" />
 </dd>
 </dl>
 <p class="Submit" style="text-align:center">
 <input type="submit" value="Continue" />
 </p>
 </div>
 </form>
 </div>
</div>​

脚本:

$( #recover-pass ).click(
       function(e){
            e.preventDefault();
            //$( #login-content ).load( /content/ResetPassword.html );
            $.ajax({
                  url:  /content/ResetPassword.html ,
                  success: function(data) {
                        $( #login-content ).replaceWith(data);
                        alert( Load was performed. );
                  }
            });
      });
最佳回答

大多数文本文件格式都会在EOF处使用最后一个换行符来保存文件。假设您像对待服务器端include一样对待这个html文件,这可能会导致您的症状。

问题回答

尝试将代码复制/粘贴到其他编辑器(如窗口中的记事本)。许多文本编辑器能够使用不同操作系统的换行符,我看到一些编辑器不能删除除设置为使用的类型之外的其他类型的换行符。例如,一个文本编辑器将Mac换行符放在文件的末尾,我在Windows中打开它,而我的文本编辑器根本不显示或指示这些换行符。记事本几乎忽略了它不知道的一切,所以当你粘贴到记事本上时,它就消除了额外的中断。

除非您看到使用ANY文件的所有AJAX请求的效果,否则这可能是罪魁祸首。





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签