Web Development with jQuery®

(Elliott) #1

AJAX Events (^) ❘ 217
street : $('textarea#addressStreet').val(),
city : $('input#addressCity').val(),
state : $('select#addressState').val(),
postalCode : $('input#addressPostalCode').val()
};
$.ajax({
url : 'Example%207-9/ADD.json',
contentType : "application/json; charset=utf-8",
type : 'ADD',
dataType : 'json',
data : JSON.stringify(data),
success : function(json, status, request)
{
if (parseInt(json) > 0)
{
alert('Data added successfully.');
}
},
error : function(request, status)
{
}
});
}
);
}
);
If you use this example with a properly confi gured server, you will note that the request is sent to
the server along with a payload of JSON formatted data that can be decoded into an object on the
server side. The screen shot shows submitting data via the ADD method to my own server, which
has been confi gured with the Access-Control-Allow-Methods HTTP header, making it possible to
submit REST requests. Figure 7-7 shows the address form.


FIGURE 7-7


http://www.it-ebooks.info

Free download pdf