cppit
cppit

Reputation: 4564

css code is removed when I tried to pass it through jquery and ajax

I am using the following code to submit different values

var evalue= 'color:#d32;font-size:12px;';
jQuery.ajax({   
    type: 'get',
    url: 'save.php',
    data: 'type=epush&id=' + qid+'&evalue='+pof+'&efield='+efield,      
    beforeSend: function() {},  
    success: function() {}
});

the issue I am having is the value needs to be css code. so when I use $eval= mysql_real_escape_string($_GET['evalue']); that strips off the code.even when I use $eval = &_GET['evalue']; it strips off the # sign. I used var evalue on javascript to make it simple to understand.

Upvotes: 0

Views: 49

Answers (1)

jmlnik
jmlnik

Reputation: 2887

You need to encode the parameters using encodeURIComponent(param), and then use urldecode() in PHP.

jQuery.ajax({   
    type: 'get',
    url: 'save.php',
    data: 'type=epush&id=' + encodeURIComponent(qid) 
        +'&evalue='+ encodeURIComponent(pof)
        + '&efield='+efield,      
    beforeSend: function() {},  
    success: function() {}
});

In PHP:

urldecode($_GET['evalue']);

Upvotes: 2

Related Questions