fdmp
fdmp

Reputation: 11

How to pass a php variable value in two php file using jquery

I need pass variable “idlaw” to base.js and then from base.js to PHP page 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);
}

Edit.php

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

Upvotes: 1

Views: 70

Answers (3)

John Bell
John Bell

Reputation: 2350

There's nothing wrong with your jQuery, it's your PHP that needs tweaking:

if( isset( $_POST['idLegislacao'] ) ) {
    $idLei = $_POST['idLegislacao'];
}

Upvotes: 0

Dmdg
Dmdg

Reputation: 1

Try with this $idLei = filter_input(INPUT_POST, 'idLegislacao');

Upvotes: 0

Denis Stiblo
Denis Stiblo

Reputation: 31

Try this code (corrected if condition and removed space in POST)

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

Upvotes: 1

Related Questions