Re: Strange string behavior...
| From: | Christoph Becker | Date: | Wed, 13 Aug 2014 18:48:07 +0000 |
| Subject: | Re: Strange string behavior... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323737@lists.php.net to get a copy of this message | ||
David OBrien wrote:
> On Wed, Aug 13, 2014 at 10:41 AM, Don Wieland <donw@dwdataconcepts.com>
> wrote:
>
>> I have an issue with updating a text field called "appt_notes" with a
>> string that uses the & and + characters. On one of the forms (which uses
>> AJAX), it does not save the entire text.
<snip>
>> $.ajax({
>> url: "/utils.php",
>>
>> type: "POST",
>>
>> data: data,
>
> on the javascript side you'd use escape( variable ) to add slashes where
> needed on all those variables
escape() is deprecated[1]; it's better to use encodeURI() resp.
encodeURIComponent() instead. However, in this case the Ajax request is
done with jQuery.ajax() so it is sufficient to set the data property to
an appropriate object[2]. Most likely it is even possible to simplify
the code considerably by using .serialize()[3].
[1]
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape>
[2] <http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings>
[3] <http://api.jquery.com/serialize/>
--
Christoph M. Becker