我需要将变量“ idlaw”传递给base.js,然后从base.js传递给PHP页面edit.php

editarLegislacao.php

<input class='btn btn-primary buttonBlue' type='button' name='btnAceitarPend' value='Edit' onClick="javascript:openAreaLaw('editLegislation', 'editlaw','<?php echo $law["idLaw"]?>')"/>


Base.js

function openAreaLaw(closeArea, openArea) {
    if ($("#" + openArea).css('display') == 'block')
        return;
    if(openArea=='applicableLegislation'){
        window.location='maps1.php';
        return;
    }
    if(openArea=='editlaw'){
      $.post({
        url: "views/editarLei.php",
            data: {
                idLaw: $("#idLaw").val()
            },
            async: true,
            success: function () {
            }
        });
    }

    $("#" + closeArea).stop().fadeOut(500);
    setTimeout(function () {
        $("#" + openArea).stop().fadeIn(500);
    }, 504);
}


编辑.php

if( isset( $_POST['idLaw'] ) ) {
    $idLaw1 = $_POST['idLaw'];
}

最佳答案

尝试以下代码(如果条件已更正,并删除了POST中的空间)

if(array_key_exists("idLegislacao", $_POST)) {
    $idLei = $_POST["idLegislacao"];
}

10-07 14:28