Questions about javascript language

Asked

Viewed 64 times

0

Good morning!

Guys, I’m a beginner in javascript and I have some questions about the section below:

var url;
function newUser(){
  $('#dlg').dialog('open').dialog('setTitle','Novo Cliente');
  $('#fm').form('clear');
  url = 'salvar_cadastroclientes.php';
}
function saveUser(){
  $('#fm').form('submit',{
    url: url,
    onSubmit: function(){
      return $(this).form('validate');
    },
    success: function(result){
      var result = eval('('+result+')');
      if (result.success){
        $('#dlg').dialog('close');		// close the dialog
        $('#dg').datagrid('reload');	// reload the user data
      } else {
        $.messager.show({
          title: 'Erro',
          msg: result.msg
        });
      }
    }
  });
}

In the save function, the code is capturing the submit of form.

And on the second line, what is this url: url, onSubmit... ?

  • 2

    It is the form action. Where to go when Submit is given.

  • 1

    That one .form() is of some plugin? in this case which?

  • The doubt is not about the language but about the algorithm.

  • exact, the doubt is about what makes this URL: URL, onsubmit :[] , Success: []

1 answer

0


**url:** *url,*

The first url is the name of an attribute. In your case the . form object has 2 attributes: **url:** e **onSubmit:** the url: is receiving the variable url, However, I believe that an error must occur, because in the scope of Function saveUser(){...} the variable url was not defined, but he was in the

function newUser(){ ... url = 'salvar_cadastroclientes.php'; }

  • Ivan, thank you so much! Another question, is Success also an attribute? on the Success line: Function(result) the result comes from where? of the return of the onsubmit?

  • There will be no error, because the variable was declared with global scope up there. The Newuser function just defines it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.