2

I am using popup for showing message based on the id of click function.so i want get the id when popup is open in php. thanks in advance

<p>Link 1</p>
<a data-toggle="modal" data-id="ISBN564541" title="Add this item" class="open-AddBookDialog btn btn-primary" href="#addBookDialog">test</a>

<p>&nbsp;</p>

<div class="modal hide" id="addBookDialog">
 <div class="modal-header">
    <button class="close" data-dismiss="modal">×</button>
    <h3>Modal header</h3>
  </div>
    <div class="modal-body">
        <p>some content</p>
        <?php //here i want to getting script variable value for database purpose?>

    </div>
</div>

and my script is

 $(document).on("click", ".open-AddBookDialog", function () {
     var myBookId = $(this).data('id');
     $(".modal-body #bookId").val( myBookId );
});

in ajax call i am getting the id from the next page but i want value in same page

function viwpost(id) { 

    var pid=id; 

    $.ajax({  
        type: "POST",  
        url: "view_more.php",  
        data: "pid=" + pid ,  
        success: function(data)
        {  
            $("#myModal21").html(data);         
        }  
    }); 
}
1
  • 2
    To get access to a javascript variable in PHP you need to use AJAX. Commented Mar 23, 2016 at 12:23

2 Answers 2

1

Since you're already using jQuery framework/API:

you can simply use the

$.get('phpfile.php' { id: myBookId }).done(function (response) { alert(response); });

your PHP file can pick the request up like this:

$_GET['id'];

If you're trying to make a live pop-up to load the data, this is an incorrect method of doing so. PHP script is only loaded once on server running and sending a request will only give you a response so ensure you research.

I'd suggest you create your PHP file to echo out the data you want to pop-up.

Demonstration of PHP file to send a response back to the request (as requested):

if(isset($_GET['id']))
{
    echo 'what ever is outputted to the client will be received in the response';
}
Sign up to request clarification or add additional context in comments.

5 Comments

how to use this..when i am using this there is no response.please give more example
Research about server-side code and client-side code. To receive a response, your server-side code needs to display something to the client. So echo "this is the response"; -> send a request and your response will be this is the response - Ill append the answer
okey..i am using the onclick function to send a id to function that want by popup <p class="pstyle1"><a onclick="view(<?php echo $mem2['pid']; ?>);"><span class="qstn" data-toggle="modal" data-target="#myModal21">View More <i class="fa fa-angle-double-right"></i></span></a></p> and this is my function: function view(id) { $.get('profile.php' { rid: id}).done(function (response) { alert(response); }); } in php:$_GET['rid']; there is no result
No, I asked if the profile.php is in the same Directory as the file you're sending the request from. Check your console for errors.
0

Hey there is mistake in getting id of the link. You can use like this -

first create input type hidden and set its id bookId in model body like this:

<input type="hidden" id="bookId" />
$(document).on("click", ".open-AddBookDialog", function () {
    var myBookId = $(this).attr('data-id');
    $(".modal-body #bookId").val( myBookId );
});

1 Comment

i want to get the id value in php.not in html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.