首页 > 解决方案 > JavaScript - jQuery.Tabledit 不适用于特定的 url

问题描述

我试图将 jQuery.Tabledit ( https://markcell.github.io/jquery-tabledit/ ) 集成到我的表中。虽然它适用于一张桌子,但另一张桌子不起作用。经过大量试验,我在更改 url 时发现了一些奇怪的东西。

我的表的基本结构:

索引.php

<script type="text/javascript" src="tabledit.js"></script>
<table id="testing">
  <thead>
    <tr id="head">
      <th>id</th>
      <th>Column 1</th>
      <th>Column 2</th>
    </tr>
  </thead>
  <tbody>
    <tr id="1">
      <th>1</th>
      <td>a</td>
      <td>b</td>
    </tr>
    <tr id="2">
      <th>2</th>
      <td>c</td>
      <td>d</td>
    </tr>
  </tbody>
</table>

<?php var_dump($_SESSION); ?>

tabledit.js

$(document).ready(function(){
    $('#testing').Tabledit({
        columns: {
            identifier: [0, 'id'],
            editable: [[1, 'Column 1'], [2, 'Column 2']]
        },

        onSuccess: function(data, textStatus, jqXHR) {
            console.log('Success');
        },

        onFail: function(jqXHR, textStatus, errorThrown) {
            console.log('Fail');
        },

        onAjax: function(action, serialize) {
            console.log('onAjax');
            console.log(action);
            console.log(serialize);
        },

        hideIdentifier: false,
        url: '../../database/test.php',
    });
});

测试.php

<?php
session_start();
$_SESSION['test'] = 'heya';
?>

现在,如果我将文件test.php放在tabledit.js旁边并将 url 代码更改为

url: 'test.php',

,会话变量不会改变,这意味着test.php根本没有运行。

如果我把它放在tabledit.js上面的一个文件夹中(例如:project/table/tabledit.jsproject/test.php)并将 url 代码更改为

url: '../test.php',

,它也不会工作。但是,如果我把它放在上面 2 个文件夹,像这样:

url: '../../test.php',

, 有用。同样的事情发生

url: '../../database/test.php',

我为此熬了一个通宵,但仍然不知道为什么。任何建议表示赞赏。

标签: javascriptjqueryajax

解决方案


推荐阅读