duan0530 2016-10-10 09:31
浏览 28
已采纳

试图通过JQuery Ajax将特殊字符发送到PHP脚本

I'm sending special characters to a PHP file via JQuery Ajax.

send_to_process.js

var special_charac = '!@#$%^&*()_+-=';
var dataString = 'data=' + special_charac;

$.ajax({
                type: "POST",
                url: "./process.php",
                data: dataString,
                cache: false,

                success: function (result) {

                }
            });

process.php

<?php

$data= $_POST['data'];
echo $data;

?>

In the PHP file I'm getting all values except + and &

Why is it so ?

Does JQuery Ajax has got some limitations as to what data can you send to PHP script ?

  • 写回答

1条回答 默认 最新

  • dongshi1207 2016-10-10 09:34
    关注

    These are not AJAX limitations. These are URL limitations. eg & is used to split parameters. Just send data as json object

    not:

    data: dataString,
    

    but

    data: {data: special_charac}
    

    or use encodeURI function to escape data

    var dataString = 'data=' + encodeURI(special_charac);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 笔记本上移动热点开关状态查询
  • ¥85 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 利用pthon计算薄膜结构的光导纳
  • ¥15 海康hlss视频流怎么播放
  • ¥15 Paddleocr:out of memory error on GPU
  • ¥30 51单片机C语言数码管驱动单片机为AT89C52