Skip to content

Instantly share code, notes, and snippets.

@jabley jabley/code.js
Created May 18, 2011

Embed
What would you like to do?
var buddy = {};
buddy.firstName=$('input[name="fname"]').val();
buddy.lastName=$('input[name="lname"]').val();
buddy.email=$('input[name="email"]').val();
var data = JSON.stringify(buddy);
$.ajax({
type: 'POST',
url: "/path/to/handler",
data: data,
contentType: 'application/json',
dataType: 'json',
success : function (data) {
// ...
},
error: function (jqXHR, textStatus, err) {
// ...
}
});

Successful input

buddy

{ firstName:"foo", lastName:"bar", email:"foo@gmail.com" };

data

'{ "firstName":"foo", "lastName":"bar", "email":"foo@gmail.com" }';

POST sends

{ "firstName":"foo", "lastName":"bar", "email":"foo@gmail.com" }

Failing input

buddy

{ firstName:"foo", lastName:"bar", email:"??@gmail.com" };

data

'{ "firstName":"foo", "lastName":"bar", "email":"??@gmail.com" }';

POST sends

{ "firstName":"foo","lastName":"bar","email":"jQuery152011057530349834899_1305758039649@gmail.com" }

and the error function is called with an err object:

"jQuery152011057530349834899_1305758039649 was not called"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.