I have a form which sent the entered values using ajax:
var form_data = {
board_id : $("#board-tabs").tabs('option', 'selected'),
name : $('#board_name').val(),
csrf_test_name : $("input[name=csrf_test_name]").val()
};
In that case form_data will be sent.
The server will return some JSON content.
Server side i’m using PHP and I’m wondering if there is some advantage sending form_data as a JSON object (considering that it must be decoded).
When you pass form data as a json object to jQuery
ajaxmethod it serializes into a string escaping all the required characters safe enough to transfer over http. It also depends on the type(GET/POST etc) you set in the ajax options.The advantage is simplicity and simple to create json object instead of building a string of key/value pair.