I want to send a few variables and a string with the POST
method from JavaScript.
I get the string from the database, and then send it to a PHP page. I am using an XMLHttpRequest
object.
The problem is that the string contains the character &
a few times, and the $_POST
array in PHP sees it like multiple keys.
I tried replacing the &
with \&
with the replace()
function, but it doesn't seem to do anything.
Can anyone help?
The javascript code and the string looks like this:
var wysiwyg = dijit.byId("wysiwyg").get("value"); var wysiwyg_clean = wysiwyg.replace('&','\&'); var poststr = "act=save"; poststr+="&titlu="+frm.value.titlu; poststr+="§iune="+frm.value.sectiune; poststr+="&wysiwyg="+wysiwyg_clean; poststr+="&id_text="+frm.value.id_text; xmlhttp.open("POST","lista_ajax.php",true); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send(poststr);
The String is:
<span class="style2">"Busola"</span>
Write an email On your Android phone or tablet, open the Gmail app . At the bottom right, tap Compose. In the "To" field, add recipients.
Click Compose from the Gmail inbox's Main Menu (left sidebar) to open the Compose window. In the To field of your new Gmail message window, type in the recipient's 10-digit cell phone number (no country code), followed by '@' and their SMS gateway address.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With