duanbairan4235 2015-12-22 05:53
浏览 44

将路径为值的php变量传递给javascript [复制]

This question already has an answer here:

I have a php variable which has path as value.I am trying to pass this url variable to javascript function.

    private function call_import_function($post_type,$fields,$fields_order,$upld_file)
{
            $uploaded_file  = $upld_file['file'];
            ?>
            <script type="text/javascript">
             jQuery(document).ready(function($) {
             var formdata = {
                            'action': 'get_csv',
                            'post_type' : '<?php echo $post_type;?>',
                            'fields' : '<?php echo $fields;?>',
                            'fields_order' : '<?php echo $fields_order;?>',
                            'uploaded_file' : '<?php echo $uploaded_file;?>',
                        };
             $.post('<?php echo $this->ajax_url;?>',formdata, function( data ) {
                            console.log("Begun!!!");
             }).done(function( data ) {
                            var obj = jQuery.parseJSON(data);

                            if(obj.error)
                            {
                                $("#column2").html(obj.error_msg);
                            }
                            else
                            {
                                console.log(data);

                                //$("#column2").html(obj.output);
                            }
                        });
             });
            </script>
<?php
}

But it gives me an error,

SyntaxError: malformed hexadecimal character escape sequence    
'uploaded_file' : 'E:\xampp\htdocs
ick\projectWed/wp-content/uploads/2'

I have tried php functions like json_encode, urlencode with $url , but non of them provided me good solution for this. I need to solve this error...

</div>
  • 写回答

5条回答 默认 最新

  • drzb7969753 2015-12-22 05:56
    关注

    You have forward slashes and backslashes mixed.

    $url = ''E:\xampp\htdocs
    ick\projectWed/wp-content/uploads/2/3.csv'
    

    should be

    $url = "E:\\xampp\\htdocs\
    ick\\projectWed\\wp-content\\uploads\\2\\3.csv";
    

    The double backslashes are required in PHP strings. They evaluate to single backslashes. This is to disambiguate them from escape sequences like (new line), \t (tab), \088 (character X), etc.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条