这段代码有什么问题? :/

发布于 2024-12-02 15:16:21 字数 3443 浏览 1 评论 0原文

我认为我的代码没问题,但是当我尝试启动绑定到 #save 输入的 ajax 调用时,它会重新加载页面,并且不会启动任何 xhr 调用:/,firebug 控制台向我显示此错误:

未捕获的异常:[异常.. 。“没有足够的参数[nsIDOMLocation.replace]”nsresult:“0x80570001(NS_ERROR_XPC_NOT_ENOUGH_ARGS)”位置:“JS框架 :: http://localhost/mysite/js/jquery.js ::; :: 第 18 行数据:无] http://localhost/mysite/js/jquery.js 第 18 行

我正在使用 jQuery 1.6.2 版本,我的代码就是这样:

<ul class="profile-account">
                    <li><h1>Account</h1></li>
                    <li><h4>Username</h4><input type="text" id="username" class="bradius3" value="<?php echo $populateUser->username; ?>"/></li>
                    <li class="error" id="error_username"></li>
                    <li><h4>Email</h4><input type="text" id="email" class="bradius3" value="<?php echo $populateUser->email; ?>"/></li>
                    <li class="error" id="error_email"></li>
                    <li><h4>Password</h4><input type="password" id="password" class="bradius3"/></li>
                    <li class="error" id="error_password"></li>
                    <li><h4>Password Confirm</h4><input type="password" id="confirm-password" class="bradius3"/></li>
                    <li class="error" id="error_password_confirm"></li>
                    <li><h4>Location</h4><input type="text" class="bradius3" id="location" /></li>
                    <li><h1>About Me</h1><textarea id="about"><?php echo $populateUser->about; ?></textarea></li>
                    <li class="error" id="error_about"></li>
                    <li><input type="submit" id="save" class="button floatRight bradiusMax" value="Save"></li>

                 </ul>

和 ajax 脚本:

var url_modify_account_xhr = "<?php echo site_url('auth/modify_account_xhr');?>";
var username;
var email;
var password;
var password_confirm;
var location;
var about;
$(document).ready(function(){
$('#users,#users span').addClass('active');
$('#myaccount').addClass('user-profile-menu-active');

$('#save').live('click',function(){
username = $('#username').val();
email = $('#email').val();
password = $('#password').val();
password_confirm = $('#password_confirm').val();
location = $('#location').val();
about = $('#about').val();
modify_account_xhr(url_modify_account_xhr,username,email,password,password_confirm,location,about);
});

});

function modify_account_xhr(url_modify_account_xhr,username,email,password,password_confirm,location,about){

   $.ajax({
        type:'POST',
        dataType:'json',
        url: url_modify_account_xhr,
        data: {'username':username,'email':email,'password':password,'password_confirm':password_confirm,'location':location,'about':about},
        beforeSend:function(){
        $('.ajax-loading').show();
       // $(_starter).attr("disabled","disabled");
        },
        success:function(json){
        $('.ajax-loading').hide();
        //$(_starter).attr("disabled","");
        }


    });
}

我真的要疯了:||

i think my code is ok but when i try to launch the ajax call binded to #save input it reloads the page and no xhr calls are launched :/ , firebug console shows me this error:

uncaught exception: [Exception... "Not enough arguments [nsIDOMLocation.replace]" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://localhost/mysite/js/jquery.js :: <TOP_LEVEL> :: line 18" data: no]
http://localhost/mysite/js/jquery.js
Line 18

i'm using jQuery 1.6.2 version and my code is simply this :

<ul class="profile-account">
                    <li><h1>Account</h1></li>
                    <li><h4>Username</h4><input type="text" id="username" class="bradius3" value="<?php echo $populateUser->username; ?>"/></li>
                    <li class="error" id="error_username"></li>
                    <li><h4>Email</h4><input type="text" id="email" class="bradius3" value="<?php echo $populateUser->email; ?>"/></li>
                    <li class="error" id="error_email"></li>
                    <li><h4>Password</h4><input type="password" id="password" class="bradius3"/></li>
                    <li class="error" id="error_password"></li>
                    <li><h4>Password Confirm</h4><input type="password" id="confirm-password" class="bradius3"/></li>
                    <li class="error" id="error_password_confirm"></li>
                    <li><h4>Location</h4><input type="text" class="bradius3" id="location" /></li>
                    <li><h1>About Me</h1><textarea id="about"><?php echo $populateUser->about; ?></textarea></li>
                    <li class="error" id="error_about"></li>
                    <li><input type="submit" id="save" class="button floatRight bradiusMax" value="Save"></li>

                 </ul>

and ajax script:

var url_modify_account_xhr = "<?php echo site_url('auth/modify_account_xhr');?>";
var username;
var email;
var password;
var password_confirm;
var location;
var about;
$(document).ready(function(){
$('#users,#users span').addClass('active');
$('#myaccount').addClass('user-profile-menu-active');

$('#save').live('click',function(){
username = $('#username').val();
email = $('#email').val();
password = $('#password').val();
password_confirm = $('#password_confirm').val();
location = $('#location').val();
about = $('#about').val();
modify_account_xhr(url_modify_account_xhr,username,email,password,password_confirm,location,about);
});

});

function modify_account_xhr(url_modify_account_xhr,username,email,password,password_confirm,location,about){

   $.ajax({
        type:'POST',
        dataType:'json',
        url: url_modify_account_xhr,
        data: {'username':username,'email':email,'password':password,'password_confirm':password_confirm,'location':location,'about':about},
        beforeSend:function(){
        $('.ajax-loading').show();
       // $(_starter).attr("disabled","disabled");
        },
        success:function(json){
        $('.ajax-loading').hide();
        //$(_starter).attr("disabled","");
        }


    });
}

really i'm going crazy :||

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

帝王念 2024-12-09 15:16:21

不,当其中一个数据值丢失或不符合预期格式时,它会抛出该错误。例如:
'用户名':用户名
username 是通过以下方式获取的:username = $('#username').val() 并且 val() 可能为空。在将数据传递给 AJAX 请求之前验证数据!

Nah, it throws that error when one of the data values are missing or is not in an expected format. For example:
'username':username
the username is get via this: username = $('#username').val() and that val() might be empty. Validate the data before passing it to the AJAX request!

心如荒岛 2024-12-09 15:16:21

您可以尝试将 $('#save').live('click',function(){ 更改为:

$('#save').live('click',function(event){
    event.preventDefault();
    // function code here
});

jQuery 1.7+ 的新增功能:

$(document).on("click", "#save", function(event){
    event.preventDefault();
    // function code here
});

You could try changing $('#save').live('click',function(){ to:

$('#save').live('click',function(event){
    event.preventDefault();
    // function code here
});

New for jQuery 1.7+:

$(document).on("click", "#save", function(event){
    event.preventDefault();
    // function code here
});
一曲琵琶半遮面シ 2024-12-09 15:16:21

我解决了,我认为这是一个 FF 问题,我刷新了很多次,现在看来没问题了:/我为这个愚蠢的错误花了半天时间:////谢谢任何人

I solved i think it was a FF problem i refreshed many many times seems ok now :/ i passed half a day for this stupid error ://// thanks anyone

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文