weixin_33704591 2015-12-07 14:14 采纳率: 0%
浏览 25

更改帖子内容

I have a file called: index.php, in which I have a form and within that form i got ajax code in which I do a call to a PHP file. This external PHP file will generate hidden input fields which will later on be appended in to my form.

This is the ajax code:

$urlforXmltoHtml = "xmltohtml.php";
$.get($urlforXmltoHtml,
  { uniquekey: Reference },
  function (data) {
    $("#Data").append(data);
    $('#msform').submit();
});

This is the div in the index.php where the generated hidden fields will be appended to:

 <div id="Data">
 </div>

In the xmltohtml.php i got this:

<?php

session_start();
$xml="";
//gebruik uniquekey van cops.php
$uniquekey = $_GET['uniquekey'];
if (file_exists('downloads/'.$uniquekey.'.xml')) {
    $xml = simplexml_load_file('downloads/'.$uniquekey.'.xml');
    foreach( $xml as $headItems )
      {

        foreach($headItems as $item){
          $_SESSION['count'] = $_SESSION['count'] + 1;
          $count =   $_SESSION['count'];
          echo '<div style="display:none;">';
          //preg replaces successive space characters
          $description = preg_replace('/\s+/', ' ', $item->->Description);
          //encoding http://php.net/manual/en/function.htmlentities.php
                 echo '<input type="hidden" name="DESCRIPTION['.$count.']" value="'. htmlspecialchars($description, ENT_QUOTES) .'">';
      echo '<input type="hidden" name="-QUANTITY['.$count.']" value="'. htmlspecialchars($item->Quantity,ENT_QUOTES) .'">';
          echo '</div>';
        }
      }
} else {

  exit('Failed to open xml.' . $uniquekey);
}
?>

but now as input when I got a $description for example witth item& then if i copy paste the html code from out chrome's element inspector I see it will be changed to item$amp; and actually when I post, I just want to post item& and not item&amp;.

any idea how I could change this so it will send & and not &amp;, or does it just send &?

  • 写回答

2条回答 默认 最新

  • 衫裤跑路 2015-12-07 14:55
    关注

    You shouldn't send URL parameters by concatenating them to the URL, but by sending them as the data parameter to jQuery's $.get:

    $urlforXmltoHtml = "xmltohtml.php";
    $.get($urlforXmltoHtml,
      { uniquekey: Reference },
      function (data) {
        $("#Data").append(data);
        $('#msform').submit();
    });
    

    On a side note, what you're doing here is very dangerous:

    $uniquekey = $_GET['uniquekey'];
    if (file_exists('downloads/'.$uniquekey.'.xml')) {
        $xml = simplexml_load_file('downloads/'.$uniquekey.'.xml');
    

    Never trust input from the client! In this case, you should whitelist a set of keys and only use those to retrieve/manipulate files on the server.

    评论

报告相同问题?

悬赏问题

  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?