weixin_33717298 2014-12-02 19:16 采纳率: 0%
浏览 21

Ajax提交不显示数据

I'm new to ajax and found a problem that i can't solve. I have a form on index.html with a input "ID" and a getdata.php that will use the ID to complete an url and use XPath to extract content of that url.

I want use ajax for that to avoid the page refresh (maybe this is not the best approach, I am open to other suggestions if this is the case) but nothing is showing when I hit the submit button, if I use the form without ajax it works fine. My code is:

Ajax

<script type="text/javascript">
    $(function () {
        $('button[type=submit]').click(function (e) {
            e.preventDefault();
            $.ajax({
                type: "POST",
                url: "getdata.php",
                data: $("#getlist").serialize(),
                beforeSend: function () {
                      $('#list').html('<img src="728.GIF" />');
                },
                success: function (data) {
                      $('#list').html(data);
                }
            });
        });
    });
</script>

form

<form class="form form-inline form-multiline" enctype="multipart/form-data" method="POST" action="" id="getlist">
   <br>
   <div class="form-group col-md-offset-4">
       <label for="id">ID</label>
       <input type="text" class="form-control" id="id" name="id" placeholder="e.g 2071">
   </div>
   <br>
   <div class="panel panel-primary">
      <div class="panel-heading">
         <h3 class="panel-title">List</h3>
      </div>
   </div>
   <div class="form-group col-md-offset-4" id="list" name="list"></div>
   <div class="col-md-12 text-right">
       <br>
       <button type="submit" class="btn btn-primary btn-default"><span class="glyphicon glyphicon-fire"></span> Submit</button>
   </div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 simulink中怎么使用solve函数?
    • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
    • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
    • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
    • ¥15 知识蒸馏实战博客问题
    • ¥15 用PLC设计纸袋糊底机送料系统
    • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
    • ¥15 用C语言输入方程怎么
    • ¥15 网站显示不安全连接问题
    • ¥15 51单片机显示器问题