I have the below code I am testing, but would like to do 2 things
1. I would like to send 2 variables from the link <a href the sendto and sentby is that possible?
I don't want to use a form, but I did think about javascript submit but didn't know how to do it.
2. How would I go at allowing the user to repeat the process, after the message has faded out, and get the same message back?
testajax.php code
I need to change the .php file a bit.
But any pointer on how to improve the code would be nice. I am new to Ajax and have got most of the code from 9lessons.info
1. I would like to send 2 variables from the link <a href the sendto and sentby is that possible?
I don't want to use a form, but I did think about javascript submit but didn't know how to do it.
2. How would I go at allowing the user to repeat the process, after the message has faded out, and get the same message back?
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("#test").click(function() {
var sendto = 1;
var sentby = 99;
var info = 'sendto=' + sendto + '&sentby=' + sentby;
$.ajax({
type: "POST",
url: "testajax.php",
data: info,
cache: false,
success: function(html) {
$("div#update").append(html);
}
});
$(".flash").fadeOut(10000);
return false;
});
})
</script>
<div id="update" class="flash"> </div>
<a href="#" id="test">test click me</a>
testajax.php code
<?php
if($_POST) {
$got = 'got';
$sendto = $_POST['sendto'];
$sentby = $_POST['sentby'];
// do something
} else {
}
?>
<div class="flash"><? echo $got; ?> test message output Send to:<? echo $sendto; ?> - Sent by <? echo $sentby; ?></div>
I need to change the .php file a bit.
But any pointer on how to improve the code would be nice. I am new to Ajax and have got most of the code from 9lessons.info
Comment