新来的jQuery,AJAX不工作 [英] New to jQuery, ajax not working

查看:87
本文介绍了新来的jQuery,AJAX不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的jQuery的,而且我可能这样做不对,但这里是我的问题。我有其中一个用户把输入框和点击提交,在响应数据将在服务器上生成并发送回用AJAX页面。但是,没事的时候我preSS提交......我知道函数被调用,所以我觉得我的jQuery的code是错误的发生。

I am very new to jQuery, and I am probably doing this wrong, but here is my problem. I have a page where a user puts input into boxes and hits submit, where response data will be generated on the server and sent back with AJAX. However, nothing happens when I press submit... I know the function is being called, so I think my jQuery code is wrong.

下面是我的code,简化为:

Here is my code, simplified:

<html>
<head>
<style type="text/css">
#hide {
    display:none;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
    $("#submit").click(doAjax());
});
function doAjax() {
    $.ajax({
        type:"GET",
        data:"myquerystring",
        url:"dummy.php"
    }).done(function(data){
        $("#hide").css("display","inline");
        $("#result").html(data);
    });
}
</script>
</head>
<body>
<p>Enter your text:</p>
<!--Code for textboxes-->
<button id="submit">Submit</button>
<p id="hide">Result:<pre id="result"></pre></p>
</body>
</html>

目前,dummy.php就是:

Right now, dummy.php is just:

<?php
echo "hi";
?>

所以这不是问题。谁能帮我这个?

so that's not the problem. Can anyone help me with this?

更新:镀铬告诉我:

 Uncaught TypeError: Object #<XMLHttpRequest> has no method 'done'

当我尝试运行doAjax()

when i try to run doAjax()

推荐答案

这是工作在我的测试。确保你的jQuery是1.5以上的版本 http://api.jquery.com/deferred.done/

It is working on my test. Make sure your jquery is version 1.5+ http://api.jquery.com/deferred.done/

jQuery的1.5

这篇关于新来的jQuery,AJAX不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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