weixin_33720452 2018-08-15 01:38 采纳率: 0%
浏览 18

jQuery AJAX变量

This should be really simple but it's after 2am and I'm struggling!

So I have a PHP file that outputs a database query in JSON format. The plan is then to use Columns (https://github.com/eisenbraun/columns) to format this JSON into a simple table.

The page has a box with a value, when clicking on this value, I want to use AJAX to get the result from my PHP script and display a table.

Currently, I have the table loading at the same time as the page;

<script>
$(document).ready(function(){

  var json1 = <?php include($inc.'xx\sp1.php');?>;
  $('#sp1').columns({data:json1});

  var json2 = <?php include($inc.'xx\sp2.php');?>;
  $('#sp2').columns({data:json2});
});
</script>

with the links on the value being;

<a class='btn btn-secondary' data-toggle="modal" href="#sp1">
<a class='btn btn-secondary' data-toggle="modal" href="#sp2">

How can I set the variables (Json1 & Json2) and load the data via an AJAX on click event? I know it's staring me in the face and it's hugely frustrating!

  • 写回答

1条回答 默认 最新

  • weixin_33743661 2018-09-11 00:32
    关注

    Really simple one to be fair but I'll use alcohol and tiredness as an excuse!

    $('#hf1djm883j').on('click',function (e){    
        $.ajax({
        type:'GET',
        url :"includes\\files\\private\\798shwo3ixxd\file6llps.php",
        dataType: 'json',
        success: function(data) {        
        $('#mmshh5e').columns({data});  
        }
        }); 
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加