I recently asked a question that was partially answered but I was hoping someone could explain this a little clearer. Its regarding PHP and the serialize function.
So I have a form with 12 fields, all with names. Traditionally I would just use the POST method, send them to a PHP page and then supply them into a database.
Today I stumbled upon the serialize method but after using it, it seems like it doesnt do anything that a regular POST statement would do. For example, if I wanted to use serialize, I would do the following:
var formData = $('#contForm').serialize();
$.post('functs.php',formData,dispAdd);
Then to print a value I would use
echo $_POST['value_name']
What I see happening is that with or without the serialize, I get the same results. Am I missing something here?
Serialization in Java allows us to convert an Object to stream that we can send over the network or save it as file or store in DB for later usage. Deserialization is the process of converting Object stream to actual Java Object to be used in our program.
Well, serialization allows us to convert the state of an object into a byte stream, which then can be saved into a file on the local disk or sent over the network to any other machine. And deserialization allows us to reverse the process, which means reconverting the serialized byte stream to an object again.
It is not secure Using XML serialization is inherently insecure. Your classes need to be public, and they need to have public properties or fields. In addition, XML serialization works by creating temporary files.
SerialVersionUID is a unique identifier for each class, JVM uses it to compare the versions of the class ensuring that the same class was used during Serialization is loaded during Deserialization. Specifying one gives more control, though JVM does generate one if you don't specify.
The .serialize() method creates a text string in standard URL-encoded notation. It operates on a jQuery object representing a set of form elements. The form elements can be of several types. Read more.
.serialize()
is used when you are sending data through an AJAX request. It's the same as submitting a form using a submit button. Only difference it when you use AJAX it does not refresh the page. That's why you get the same results even though you submit the form using a submit button or .serialize()
when using AJAX.
.serializeArray() would be an alternative to .serialize()
.
Remember if you don't use .serialize()
you have to create your key-value pairs manually as @Akam mentioned in the comment above.
And finally
When to use serialize <-- When you use AJAX to post data
When regular POST <-- When you use submit button to post data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With