最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - PHP Get button $_POST value when clicked - Stack Overflow

programmeradmin0浏览0评论

OK I might be a bit out of my depth here I have a page like this:

Now When Someone clicks the button a fancy sliding page "slides" over the current page, asking for the user to enter his application details.

Now I need to get the clicked Button's value which contains the jobID primary key inorder for me to process the application data...makes sense?

What I would like to know is, since no actual page is loaded and no data gets send, (its only css & jquery providing a "modal" for the application page).

How would I go about finding the value of button. Im not sure where to start really?

  1. Is it possible getting it with PHP alone? (again keeping in mind no actual data gets send)?
  2. Can the value be retrieved with AJAX?
  3. Would it require some sort of pletely different language like node.js or similar?

Any tips / advice / references appreciated

OK I might be a bit out of my depth here I have a page like this:

Now When Someone clicks the button a fancy sliding page "slides" over the current page, asking for the user to enter his application details.

Now I need to get the clicked Button's value which contains the jobID primary key inorder for me to process the application data...makes sense?

What I would like to know is, since no actual page is loaded and no data gets send, (its only css & jquery providing a "modal" for the application page).

How would I go about finding the value of button. Im not sure where to start really?

  1. Is it possible getting it with PHP alone? (again keeping in mind no actual data gets send)?
  2. Can the value be retrieved with AJAX?
  3. Would it require some sort of pletely different language like node.js or similar?

Any tips / advice / references appreciated

Share Improve this question asked Apr 15, 2017 at 4:38 MarileeMarilee 1,5984 gold badges23 silver badges54 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

This ajax example help you you get your click value you have to set onclick button attribute in your html.

<script type="text/javascript">

  function loadajax(value){
      if (window.XMLHttpRequest) {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp = new XMLHttpRequest();
      } else {
          // code for IE6, IE5
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      var pid = value;
      alert(pid);
      var queryString = "?send your primary key id or jobid=" + pid;
      xmlhttp.open("POST","Page name" + queryString,true);
      xmlhttp.send();
    }

</script>
  1. Yes. PHP can return to you only a JSON data
  2. Yes, You can do AJAX
  3. No. PHP, HTML, CSS, JavaScript are enough. Maybe you can use Bootstrap css framework and JQUERY I remend: You can use html decoration. Its mean: to define your own HTML attributes. Example:

    <a class="view" href="javascript:;" data-id="111" >VIEW</a>

Javascript code:

<script language="JavaScript">
     $("a.view").click(function(){
            var jobId = $(this).attr("data-id");
            $.ajax({
                url: "[YOUR_URL]",
                data:{"job_id":jobId},
                type:"post", 
                success:function(response){
                    //You must open your css modal window and fill
                } 
            })
     }); 
</script>

PHP code:

<?php
header('Content-Type: application/json; charset=utf-8');
$responseData = []; // you fill this variable with response data
echo json_encode($responseData);

For your apply button , have an onclick registered to some function in javascript along with the event passed in the given manner :

<button value="(whatever)" onclick ="sendreq(event)" >

Now in your javascript , have a function sendreq(e) :

 function sendreq(e)
 {
   var jobId = e.target.value;
   //Process your data however with this jobId you have
   //Make XMLHttpRequest() and open a post ajax call of your choosing.

 } 

The variable jobId will contain what you require .

1st you can not show the module where you set jobID.

If you want to get directly JobID then try '$_POST[]' method in URL itself like http://yourURL.Domain/?id='jobId' and it will directly move or use for next page as well as current page also. . .

But in that way JobID will show in URL. :(

if You want to go on AJAX then it is better. . .

otherwise try html+php I hope that is useful . . .

<!-- this is Simple code for idea what i say. . .-->
  <html>
    <body>
     <form action="#" method="post">
       <input type = "XYZ" id="JobID">
       <input type = "Submit" value="submit">
      </form>
    </body>
  </html>

   <?php 
        if(isset($_POST['JobID']))
         //USE JobID 
    ?>
发布评论

评论列表(0)

  1. 暂无评论