I\'m using jQuery.ajax to extract form data from a page, and send it to my database (via another PHP page).
The form information is collected by:
var
encodeURIComponent will do what you are looking for.
var X = encodeURIComponent($('#div1').val()); var Y = encodeURIComponent($('#div2').val());
This will encode all potentially insecure characters.