首页 > 解决方案 > 如何使用ajax从选定的行中获取id

问题描述

我有两页,第一页您可以在其中查看信息,然后单击行的编辑图标,它将转到带有 id 的第二页以显示数据。第二页显示数据后,您可以更新数据等。

按钮单击在查看文件代码中获取 id

查看文件代码

编辑文件代码

标签: phpajaxoopcrud

解决方案


您可以从 Url 获取 id。使用此 id 并通过 ajax on call 将数据填充到编辑表单中$( window ).load(function() {// Run code});.

 var getUrlParameter = function getUrlParameter(sParam) {
            var sPageURL = window.location.search.substring(1),
                sURLVariables = sPageURL.split('&'),
                sParameterName,
                i;
  for (i = 0; i < sURLVariables.length; i++) {
            sParameterName = sURLVariables[i].split('=');

            if (sParameterName[0] === sParam) {
                return sParameterName[1] === undefined ? true : 
            decodeURIComponent(sParameterName[1]);
            }
        }
    };

    id = getUrlParameter('Edit');
    console.log(id);//check console

推荐阅读