dongxieyi9115 2016-12-06 13:59
浏览 25

如何将.xml从jQuery传递给PHP?

I'm using jQuery.ajax() to submit a form on my website. I get an .xml response and I want to send it to a .php file. I've tried using another jQuery.ajax() function:

<script type="text/javascript">
  $(document).ready(function() {
    $('#form').submit(function(e) {
      e.preventDefault();

      $.ajax({
        type: 'POST',
        url: 'myURL',
        data: $('#form').serialize(),
        success: function(xml)
        {
          $.ajax({
            type: 'POST',
            url: 'saveData.php',
            data: {
              xml: $(xml),
            },
            success: function(data) {
              $('#output').html(data);
            }
          });
        }
      });
    });
  })
</script>

but I faced "Illegal invocation" error. So I added processData: false to my inner AJAX function. Now I get another error: Undefined index: xml in... Here is my PHP code:

<?php
  $xml = $_POST['xml'];
?>

How to manage this issue?

  • 写回答

2条回答 默认 最新

  • dougupang0901 2016-12-06 14:06
    关注

    What you can try is specify in the first $.ajax call that you are going to receive an XML using dataType :

    $.ajax({
        type: 'POST',
        url: 'myURL',
        dataType: 'xml,
        data: $('#form').serialize(),
        success: function(xml) (...)
    

    But I have a question. Why using an ajax into an other ajax call ? If both are made to the same server, it dont seems legit.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?