Reputation: 8826
I'm reading the value of an input text field and passing it to be used as ajax data
The field value has a +
<input name="someval" type="text" value="Receive (+ open)" />
and looks like when parsed with data, it parses the + as a jquery concatenation.
data: 'someval=' + $("input[name=someval]").val(),
This is the first time I notice this behavior.
Thanks
Upvotes: 0
Views: 244
Reputation: 24085
Try encodeURIComponent
:
'someval=' + encodeURIComponent($("input[name=someval]").val())
Better yet, let jQuery handle it for you:
data: { someval:$("input[name=someval]").val() }
jQuery will automatically escape your values (and keys) into the correct format (using jQuery.param()
) for the data type (eg "application/x-www-form-urlencoded"
).
Upvotes: 2