简体   繁体   English

当我试图通过jquery和ajax传递它时,删除了css代码

[英]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. 我遇到的问题是价值需要是css代码。 so when I use $eval= mysql_real_escape_string($_GET['evalue']); 所以当我使用$eval= mysql_real_escape_string($_GET['evalue']); that strips off the code.even when I use $eval = &_GET['evalue']; 当我使用$eval = &_GET['evalue']; _GET $eval = &_GET['evalue'];时,剥离代码$eval = &_GET['evalue']; it strips off the # sign. 它剥掉了#符号。 I used var evalue on javascript to make it simple to understand. 我在javascript上使用var evalue使其易于理解。

You need to encode the parameters using encodeURIComponent(param) , and then use urldecode() in PHP. 您需要使用encodeURIComponent(param)对参数进行编码,然后在PHP中使用urldecode()

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

In PHP: 在PHP中:

urldecode($_GET['evalue']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM