weixin_33744854 2015-02-18 19:35 采纳率: 0%
浏览 40

jQuery.ajax替换PHP代码

I'm trying to update a REST search result with ajax to not reload a new page.

right now search result is shown within:

<div id="searchtable"><?php include 'hotels/hotelList.php';?></div>

On click on button I want to reload this div element so it includes a new php file.

Button:

<button onclick="myFunction()">LOAD</button><br /><br />

jQuery

<script>
function myFunction() {
  $.get( "/hotels/hotelSortBy.php" );
  $('#searchtable').replaceWith('<?php include 'hotels/hotelSortBy.php';?  >');
 }
</script>

I'm not able to replace the div element "searchable" - with replaceWith - Am I doing this right ?

  • 写回答

3条回答 默认 最新

  • weixin_33719619 2015-02-18 19:38
    关注

    There's no need for inline PHP if you're using AJAX. Try using jQuery's .load AJAX method:

    function myFunction() {
      $('#searchtable').load('/hotels/hotelSortBy.php');
    }
    

    Note that this is slightly different than .replaceWith -- using .load will preserve #searchtable and put the new content inside of it, rather than replacing it.

    评论

报告相同问题?

悬赏问题

  • ¥15 vc6.0中想运行代码的时候总是提示无法打开文件是怎么回事
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题