Implementation of ajax-technology



  • Good day!
    There's a form of registration. There's a violin:

     $(function() {
        $("#form-regis").submit(function(e) {
          e.preventDefault();
    
      var formURL = $(this).attr("action");
      var formmethod = $(this).attr("method");
      var postData = $(this).serialize();
    
    $.ajax({
        type: formmethod,
        url: formURL,
        data:postData,
        cache: false,
    
        success: function (data) {
            console.log(data);
        }
    
    });
    
    return false;
    

    });
    });

    My little knowledge. JavaScript and jQuery Don't leave me with the opportunity to put it on the page. Modified window registration form, so no Ajax I don't want to be here. In the console, I take a lot of mistakes, that's what I'm allowed to fill the form. Help me get them on the page. First, we'll have to deal with this, and then we'll have to hide the form in the absence of mistakes, and we'll have to make sure that the record is successful and that the letter of confirmation is sent to the post office.

    I'm sorry for the incomplete infu. Data are available in JSON, in a field: a set/object of error.

    I've done it now:

    success: function (errors) {
    console.log(errors);
    var out = '';
    if (errors[0].name) out += "<p>"+errors[0].name+"</p>";
    if (errors[0].email) out += "<p>"+errors[0].email+"</p>";
    if (errors[0].password) out += "<p>"+errors[0].password+"</p>";

    $('#errors-block').html(out).fadeIn();
    

    }

    But if you don't make mistakes, it's like that:

     Uncaught TypeError: Cannot read property 'name' of undefined

    Laravel 5



  • success: function (errors) {
        console.log(errors);
        var out = '';
        for(err in errors) {
           out += "<p>"+errors[0][err]+"</p>"
        }
        if(out != '') {
           $('#errors-block').html(out).fadeIn();
        }
     }
    

    If (errors[0].name) return the error if there is no such characteristic, it's necessary to check.

    if(typeof errors[0].name !== 'undefined')




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2