The AJAX side of that can be done, but what's the point?
I ask because:
PHP Code:
<?php
$field1value = ajaxy stuff;
?>
contrary to what you assert in your post, doesn't store anything. Like any PHP page, regardless of where it gets its information from, doing that only assigns a value to $field1value while the page that variable is on is being processed.
That's not to say that doing something generally like that cannot be of any worth, it can. But there needs to be a more concrete purpose.
So let's forget about what happens on the PHP page for a moment. AJAX is vastly less complicated when we use jQuery. So on the 'sending' page we can have:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function($){
var field1 = $('#field1');
$('#send').click(function(){
if(!field1.val()){
alert("Please enter a value");
field1.focus();
return;
}
jQuery.ajax({
url: 'somepage.php',
type: 'post',
data: 'field1value=' + field1.val()
});
});
});
</script>
</head>
<body>
<body>
<input type="text" name="field1" id="field1">
<input type="button" value="Submit" id="send">
</body>
</body>
</html>
And on the 'receiving' page (somepage.php):
PHP Code:
<?php
$field1value = isset($_POST['field1value'])? $_POST['field1value'] : '';
?>
But, as I say it doesn't do anything. The somepage.php code runs on the server, the $field1value is set, then the page is done and all is forgotten. Nothing has changed or happened other than a few clock ticks got used up on the server.
If on the other hand we use a 'sending' page like:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
jQuery(function($){
var field1 = $('#field1');
$('#send').click(function(){
if(!field1.val()){
alert("Please enter a value");
field1.focus();
return;
}
jQuery.ajax({
url: 'somepage.php',
type: 'post',
data: 'field1value=' + field1.val(),
success: function(results){
alert(results);
}
});
});
});
</script>
</head>
<body>
<body>
<input type="text" name="field1" id="field1">
<input type="button" value="Submit" id="send">
</body>
</body>
</html>
And on somepage.php:
PHP Code:
Hey, what did you type "<?php
$field1value = isset($_POST['field1value'])? $_POST['field1value'] : '';
echo $field1value;
?>" for?
Now we at least have evidence that something happened.
Bookmarks