1

Working on a username availability function. For an existing user changing their username I want to pass the new username and the ID of the person to a remote function. This function works fine on the backend (if the ID is included it looks for the username excluding the ID).

Add the ID (hidden form field with ID = sid) throws a stack overflow error "maximum call stack size exceeded". What's the proper way to pass both the user's ID and the proposed new username?

new_username: {
  remote: {
    url: [url to function],
    type: 'post',
    data: {'sid':sid, 'new_username':new_username},
    dataFilter: function(data, type){
        return type == 'json' ? data.replace(/^(\/{2})?/, '') : data;
    }
  }
}

The HTML form looks like this:

<form class="stdForm" id="jqv" name="stForm" action="" method="post">
    <input type="hidden" name="sid" id="sid" value="12345"/>
    <div>
      <label for="new_username">Login Username</label>
      <input type="text" name="new_username" id="new_username" value="[current username]" />
    </div>
    <div>
        <input type="submit" value="Update"/>
    </div>
</form>

The full javascript is a long jquery validation script. The fields "new_username" and "sid" are not referenced anywhere else in the form. When I just send the username (without the ID) I have a separate rule set that works:

username_check: {
  remote: {
    url: [url to function],
    type: 'post',
    dataFilter: function(data, type){
        return type == 'json' ? data.replace(/^(\/{2})?/, '') : data;
    }
  }
}

Where username_check is the ID of the field in the form.

3
  • What are the values of sid and new_username? Commented Feb 25, 2019 at 15:28
  • If its stack overflow error then 90% chances arevyou are calling a jquery function / registering event multiple times in recursion. Can you paste the full js code ? Commented Feb 25, 2019 at 15:31
  • You're doing it wrong. You need a function to return the value. Just follow the second example in the docs. Commented Feb 25, 2019 at 16:55

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.