How to encode and submit local variables via ajax POST?
I have a collection of local variables populated via Flash movies and scripts, and now I need to submit an ajax post (can also be get, but prefer post).
I have tried:
- $.ajax({
type: "POST",
url: "/myurl",
data: "p1=" + localParam1 + "&p2=" + localParam2,
success: function(msg){
alert( Bingo: " + msg );
}
});
The problem with this is the encoding of the localParam1 and localParam2 sometimes breaks the normal & delimeters. An even more problem is I sometimes have upwards of 25+ local variables that I need to submit. These inline +s makes it feel, and look, like one huge hack - not to mention the encoding.
One last restriction: I cannot use any jquery plugins due to the company's policy. So, I'm looking for something small and light as a solution - not a plug-in, please.
Isn't there an easy way to do this?
ONe thought I had was to create a new <form> on the page, and insert the variables as new <input /> fields - and then finally submit the entire form. Again, a big hack + css - but it would get around the encoding issue.
Got to be an easier way...