jquery serialize to php code example

Example 1: jquery serialize

var datastring = $("#contactForm").serialize();
$.ajax({
    type: "POST",
    url: "your url.php",
    data: datastring,
    dataType: "json",
    success: function(data) {
        //var obj = jQuery.parseJSON(data); if the dataType is not specified as json uncomment this
        // do what ever you want with the server response
    },
    error: function() {
        alert('error handling here');
    }
});

Example 2: jquery serialize php decode

//the GET parameter is the data outputted from jQuery's .serialize() function
$params = array();
parse_str($_GET, $params);

Tags:

Php Example