Reputation: 399
I have form inputs in a table row, which I would like to submit via ajax.
$(this).closest("tr").find("input,select,textarea").each(function(){$data+=$(this).attr('name')+'='+encodeURIComponent($(this).val())+'&';
I had everything working fine - until one of the inputs had an ampersand in the value. I found some information on this post, which helped a lot - and using encodeURIComponent (as shown above) I was able to get the form to submit without a problem. My question is - in that post, @T.J. Crowder mentioned how he would "strongly recommend" using @Darin Dimitrov's solution:
data: { id: thisId, value: thisValue }
How would I implement this in my current code? Also - is there any benefit to using the second code, or is encodeURIComponent just as good?
Upvotes: 0
Views: 399
Reputation: 146
You can use the native Javascript "Object" pseudo-class. I don't really understand your code's purpose; but, supossing it is correct, should look like this:
$data = new Object;
$(this).closest("tr").find("input,select,textarea").each(function(){
$data[$(this).attr('name')] = $(this).val();
});
Hope this helps.
Upvotes: 1