kuanhsuh
8/17/2017 - 2:18 AM

great way to use jquery ajax

great way to use jquery ajax

submitToServer = (e) =>{
    e.preventDefault()
    const submitData = {
      "app_nickname": this.state.nickname,
    }
    secretAjax({
      url: API_URL.CHANGENICKNAME,
      data: submitData,
      type: 'POST',
      dataType:'text'
      }, {
      success: (res) => {
        sweetAlert({
          title:"成功",
          text: res.app_message,
          confirmButtonText:"确定",
          type: "success"
        }, (isConfirm) => {
          if(isConfirm) {
            window.location.href='/defaultm_indexpage.shtml?flag=accountinfo'
          }
        });
      },
      fail: () => {

      },
      errorAlert: (res) => {
        swal({
          title: '糟糕',
          text: res.app_message,
          type: 'error',
          confirmButtonText: '确定'
        }, () => {

        })
      }
    })
  }