vendredi 13 février 2015

get post jquery and echo it in $_POST(is that possible?)


I'm learning how to post data to server.I want to click on a link and post its data to the server in the same page, do I need to have a form to do that? is it possible to post data without having a form? I cannot see the result in php should I have any success or done function here to have the results? I also have tried Last example of Jquery manual and there is no content div to see any results and so I couldn't figure it out.


I do not want to show data and append it in the html I want to see it in $_POST and if it is not possible to show it in the same page I am ok with that all I want is to see $_POST can have the data from JQUERY



<?php
if(isset($_POST["name"]))
echo $_POST["name"];
?>
<!DOCTYPE html>
<html>
<head>
<script src="http://ift.tt/1xDNnh9"></script>
<script>
$(document).ready(function(){

$("#link").click(function(){
$.post("newfile5.php",
{
name: $("#link").val()
}


});
$('form#myform').submit();
});
</script>
</head>
<body>
<form id="myform" action="newfile5.php" method="POST">
<a id="link" href="" value="A">Send</a>
</form>
</body>
</html>


PS:I updated upon answers, and still not result:



<?php
if(isset($_POST["name"]))
echo $_POST["name"];
?>
<!DOCTYPE html>
<html>
<head>
<script src="http://ift.tt/1xDNnh9"></script>
<script>
$(document).ready(function(){

$("#link").click(function(e){
e.preventDefault();
$.post("newfile5.php",
{
name: $("#link").data("value")
},
function(data)
{
// Whatever is returned by newfile5.php
}

});
});
</script>
</head>
<body>
<a id="link" href="" data-value="A">Send</a>

</body>
</html>


I expect to see $_POST['name'] having the value A, just this





Aucun commentaire:

Enregistrer un commentaire