Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP / jQuery - single quote doubled in Ajax call
    primarykey
    data
    text
    <p>I hope this is not a duplicate, but all other problems with single quote in jQuery-Ajax-calls were talking about errors, not about what I observe here.</p> <p>I have a Problem with jQuery-Ajax-calls which contain a single quote in the sent parameters - those are always doubled on the server side! I wrote a small playground-script, containing both front- and backend, to show the problem:</p> <p><strong>playground.php</strong></p> <pre><code>&lt;?php if(isset($_REQUEST["foo"])) { ?&gt; &lt;root&gt; &lt;fooVal&gt; &lt;?php echo $_REQUEST["foo"]; ?&gt; &lt;/fooVal&gt; &lt;/root&gt; &lt;?php die; } ?&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;script type="text/javascript" src="jquery-1.7.2.min.js"&gt;&lt;/script&gt; &lt;script&gt; function testSend() { $.ajax({ type: "get", url: "playground.php", data: {"foo" : $("#fooInput").val()}, success: function(data) { $("#fooResult").text($(data).find("fooVal").text()); } }); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="text" id="fooInput" /&gt; &lt;a href="javascript:testSend()"&gt;send&lt;/a&gt; &lt;div id="fooResult"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>If I enter into the input field for example:</p> <pre><code>L'eclisse </code></pre> <p>The div#fooResult contains after the AJAX-call:</p> <pre><code>L''eclisse </code></pre> <p>So somehow the script made two single quotes out of one. Examining with firebug, I see that the Parameter is sent correctly with only one single quote. But the answer always contains two of them, no matter if I output (in the PHP part on the top of the script) in XML or via json_encode or just a plain echo.</p> <p><strong>What I already tried:</strong></p> <ul> <li>using <code>encodeURI(($"#fooInput").val())</code> - no change</li> <li>using <code>encodeURIComponent(($"#fooInput").val())</code> - no change</li> <li>using <code>escape($("#fooInput").val())</code> - this will output L%27eclisse </li> </ul> <p>Does anyone have a suggestion, what I might do? Either on the client (javascript) side or on the server (php) side of the script? Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload