Using ajax to send form data to php

后端 未结 3 873

I want to send form data from ajax to php. My ajax retrieves the form data but it doesnt send it i dont see anything wrong with the code maybe i need a much more professional he

3条回答
  •  庸人自扰
    2021-01-22 21:29

    I solved it works this way on the php side you do this

    $name =  isset(json_decode($_POST['username']));//htmlentities($values[0]);
    $email =  isset(json_decode(($_POST['email'])));//htmlentities($values[1]);
    $password =  isset(json_decode($_POST['password']));//htmlentities($values[2]);
    

    The Ajax side

    $(document).ready(function(e) {
    
       $('#signup').live('click', function(){
           //var name = document.getElementById('Susername').value;
           //var email = document.getElementById('Semail').value;
           //var pass = document.getElementById('Spassword').value;
           var that = $('form.check-user'),
           urls = that.attr('action'),
           methods = that.attr('method'),
           data = {};
          data = that.serialize();
            console.log(data);
    
    
           $.ajax(
        {
            url: urls,
            type: methods,
            dataType:'json',
            data : data,
            beforeSend: function(response){$.mobile.showPageLoadingMsg(true);},
            success: function(response){ $.mobile.showPageLoadingMsg(false);},
            error: function(xhr, textStatus, errorThrown){alert(textStatus);},
            complete: function(response){},
        }
        );
           return false;
           });
    

    });

提交回复
热议问题