问题
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?
- Is it possible getting it with PHP alone? (again keeping in mind no actual data gets send)?
- Can the value be retrieved with AJAX?
- Would it require some sort of completely different language like node.js or similar?
Any tips / advice / references appreciated
回答1:
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>
回答2:
- Yes. PHP can return to you only a JSON data
- Yes, You can do AJAX
No. PHP, HTML, CSS, JavaScript are enough. Maybe you can use Bootstrap css framework and JQUERY I recommend: 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);
回答3:
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 .
回答4:
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
?>
来源:https://stackoverflow.com/questions/43422248/php-get-button-post-value-when-clicked