How can I send the "&" (ampersand) character via AJAX? How can I send the "&" (ampersand) character via AJAX? ajax ajax

How can I send the "&" (ampersand) character via AJAX?


You can use encodeURIComponent().

It will escape all the characters that cannot occur verbatim in URLs:

var wysiwyg_clean = encodeURIComponent(wysiwyg);

In this example, the ampersand character & will be replaced by the escape sequence %26, which is valid in URLs.


You might want to use encodeURIComponent().

encodeURIComponent(""Busola""); // => %26quot%3BBusola%26quot%3B


You need to url-escape the ampersand. Use:

var wysiwyg_clean = wysiwyg.replace('&', '%26');

As Wolfram points out, this is nicely handled (along with all the other special characters) by encodeURIComponent.