JQuery的未确认前$ P $关于Ajax响应pssion [英] JQuery unrecognized expression on Ajax response

查看:122
本文介绍了JQuery的未确认前$ P $关于Ajax响应pssion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个jQuery Ajax表格。

I have this JQuery Ajax Form.

$('#modal-body-sign-in').on('submit', '#sign-in', function(e) {
        e.preventDefault();
        var data = $(this).serialize();
        var url = $(this).attr('action');
        $.ajax({
            //this is the php file that processes the data and send mail
            url : url,
            type : "POST",
            data : data,
            dataType: "html",
            //Do not cache the page
            cache : false,
            //success
            success : function(data) {
                //console.log(data.content);

                console.log($(data));
                //$('#modal-body-sign-in').html(data);
            }
        });
    })

上的反应,当我的console.log(数据);在控制台它显示我的回答HTML 但是当我做这个的console.log($(数据)); 它给了我这个错误

on the response, when i console.log(data); in the console it shows me the responded html but when I do this console.log($(data));it gives me this error

未捕获的错误:语法错误,无法识别的EX pression:

Uncaught Error: Syntax error, unrecognized expression:

<html>
<head>
<style>
ul {
    margin: 0%;
}

ul li {
    display: inline;
    list-style-type: none;
    float: left;
}
</style>
<title>Insert title here</title>
</head>
<body>
    <!--  Ajax Container. DO NOT REMOVE THE DIV CONTENT  FOR AJAX ACCESS! -->
    <div id="content">
        <div id="modal-body">

            <form id="doLogin" name="doLogin" action="/HitPlay/doLogin" method="post">

                <fieldset>
                    <ul id="doLogin_" class="errorMessage">
            <li><span>Incorrect username or password</span></li>    </ul>

                <br/>           

                <br/>

                    <label>Username</label>                 
                    <input type="text" name="userBean.username" value="" id="doLogin_userBean_username"/>
                    <br/>
                    <label>Password</label>
                    <input type="password" name="userBean.password" id="doLogin_userBean_password"/>
                    <br />

                    <input type="submit" id="doLogin_0" value="Submit"/>

                </fieldset>
            </form>





        </div>

    </div>
</body>
</html> jquery-1.9.0.min.js:2
a.error jquery-1.9.0.min.js:2
f jquery-1.9.0.min.js:2
x jquery-1.9.0.min.js:2
a jquery-1.9.0.min.js:2
st.fn.extend.find jquery-1.9.0.min.js:2
st.fn.st.init jquery-1.9.0.min.js:1
st jquery-1.9.0.min.js:1
$.ajax.success localhost:59
f jquery-1.9.0.min.js:1
p.fireWith jquery-1.9.0.min.js:1
r jquery-1.9.0.min.js:3
r

我这样做

  $(data) 

因为我想要得到的回应HTML页面的一个片段

because I want to get a fragment of the responded HTML page

推荐答案

我有完全相同的问题,因为我已经升级到jQuery的1.9.x中其实简单的$(数据)产生的碰撞,没有别的。我有这个问题之前(不含previous版本比1.9)几次,但我不记得它的问题...

I've got exactly the same problem since I've upgraded to jQuery 1.9.x. actually the simple $(data) generates the crash, nothing else. I had this problem a few times before (without previous versions than 1.9), but I don't remember its issue...

反正它是一个完全阻塞麻烦......还在寻找一个理由和修复。

anyway it is a totally blocking trouble... still looking for a reason for that and a fix.

编辑:

如果我这样做了:

$.ajax('/',function(html){
  html = $('<div></div>').append(html);
  $(html);
});

它工作正常。 如果我做的:

It works fine. If I do :

$.ajax('/',function(html){
  $(html);
});

这给了我(通过FF错误控制台):

It gives me a (through the FF error console) :

Erreur : Error: Syntax error, unrecognized expression: <div id="...">(...)
jquery.min.js - line : 4

编辑2:

确定找到了解决办法...一个漫长的探索和试验后: <一href="http://stage.jquery.com/upgrade-guide/1.9/#jquery-htmlstring-versus-jquery-selectorstring">http://stage.jquery.com/upgrade-guide/1.9/#jquery-htmlstring-versus-jquery-selectorstring

Ok found the solution... after a long search and tests : http://stage.jquery.com/upgrade-guide/1.9/#jquery-htmlstring-versus-jquery-selectorstring

所以,我现在做的是这样的:

So I now do something like :

$.ajax('/',function(html){
  $($.parseHTML(html));
});

反正jQuery的总是困惑我的第一个元素之一,但至少它的工作原理

Anyway jQuery is always confusing my first element with the one, but at least it works

这篇关于JQuery的未确认前$ P $关于Ajax响应pssion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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