2

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 :||

itsme
  • 48,972
  • 96
  • 224
  • 345

3 Answers3

5

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!

3

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
});
Ash Clarke
  • 4,807
  • 1
  • 37
  • 48
  • 1
    Note there is a difference between `return false;` and `preventDefault()` http://stackoverflow.com/questions/1357118/javascript-event-preventdefault-vs-return-false/1357151#1357151 Generally I would say `return false` fits most use cases in this scenario. – jondavidjohn Sep 01 '11 at 14:41
  • 1
    I said to try event.preventDefault because it is called before your code is executed, however, return false is called after. Return false is often [misused](http://fuelyourcoding.com/jquery-events-stop-misusing-return-false/) too, so I shy away from it. – Ash Clarke Sep 01 '11 at 14:49
  • thanks guys but here i think there is somenthing really strange i tryed both your solutions, but firebug continue to show me an exception error that i didn't receive in any other of my xhr functions, really strange :/ – itsme Sep 01 '11 at 14:56
  • 1
    Have you tried Break On Error on the Firebug console? Click the break on error (pause) button (```next to clear```) on the far left after clicking the Console tab. http://getfirebug.com/doc/breakpoints/error_in_console_set_break.jpg – Ash Clarke Sep 01 '11 at 15:07
1

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

itsme
  • 48,972
  • 96
  • 224
  • 345