weixin_33699914 2016-12-13 12:58 采纳率: 0%
浏览 17

绑定输入类型提交

I have Registration.html fail, which contains registration form. The other failure is in KinveyRequester.js

function registerUser(e) {
    e.preventDefault();

    let userData = {
      username: $("#registerUsername").val(),
      password: $("#registerPassword").val()
    };
    $.ajax({
      method: "POST",
      url: kinveyBaseUrl + '/user/' + kinveyAppKey,
      headers: kinveyAppAuthHeaders,
      data: userData,
      success: registerSuccess,
      error: handleAjaxError
    });

    function registerSuccess(userInfo) {
      saveAuthInSession(userInfo);
      showInfo("User Successfully Registered");
    }

The Question is:

How can i bind and when i clicked "Register" button it runs correctly and register a user. Here is the Register.html fail

  • 写回答

3条回答 默认 最新

  • weixin_33725239 2016-12-13 13:05
    关注

    You can bind registerUser function with your submit button simply by using jQuery on() method:

    $(document).ready(function() {
        $('#reg-btn').on('click', registerUser);
    });
    

    But it's better to bind on form's submit event:

    $(document).ready(function() {
        $('#your-form').on('submit', registerUser);
    });
    

    but in that case you have to return false at the end of the your registerUser function in order to prevent default submit behaviour.

    评论

报告相同问题?