1

I use Ajax to retrieve a string from database that has an ampersand characher "&", like this: "Dual-core 2.15 GHz Kryo & Dual-core 1.44 GHz Kryo"

document.getElementById("cpu'.$i.'").value = $(this).nextAll().eq(2).text();

I display the text inside an input field and i can see it correctly. Then, i try to send it to other page, with POST method and here i get "403 Error"...

$cpu=$_POST['cpu'.$p];

I know it's the ampersand character because i had the same problem with double quotes, which i resolved it like this:

htmlentities(stripslashes(utf8_decode($display)))

But i don't know how to escape this ampersand... I looked to other posted questions here but nothing seems to work..

help please...

The solution was posted as similar is not working for me...

I'll give you more code:

<?php
for($i=1; $i <= 9; $i++){
${'content' . $i}='<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">

$(function(){
$("#searchid'.$i.'").keyup(function() 
{ 
var searchid'.$i.' = $(this).val();
var dataString = \'search=\'+ searchid'.$i.';
if(searchid'.$i.'!=\'\')
{
    $.ajax({
    type: "POST",
    url: "searchspecs.php",
    data: dataString,
    cache: false,
    success: function(html)
    {
    $("#result'.$i.'").html(html).show();

    $(".name").click(function(){
    document.getElementById("brand'.$i.'").value = $(this).nextAll().eq(7).text();
    document.getElementById("model'.$i.'").value = $(this).nextAll().eq(6).text();
    document.getElementById("id'.$i.'").value = $(this).nextAll().eq(0).text();
    document.getElementById("storage'.$i.'").value = $(this).nextAll().eq(1).text();    
    document.getElementById("cpu'.$i.'").value = $(this).nextAll().eq(2).text();

....

and then:

$cpu=$_POST['cpu'.$p];

One more problem... I receive 403 forbidden error also if i have "or" in text, for example: "16 GB, 32 GB, or 64 GB"

chitoiu daniel
  • 107
  • 2
  • 13
  • 1
    Possible duplicate of [How do I escape an ampersand in a javascript string so that the page will validate strict?](http://stackoverflow.com/questions/355043/how-do-i-escape-an-ampersand-in-a-javascript-string-so-that-the-page-will-valida) – TIGER Jan 11 '17 at 09:08

0 Answers0