使用jQuery和PHP为ajaxForm()传递两个值

时间:2010-01-27 19:57:13

标签: php jquery

我想使用ajaxForm传递这两个值,在test.php中分别显示两个值

-------test.php-----------------------------------------

<script language="javascript" type="text/javascript">

$('#test_form').ajaxForm({
    target:'#result',

    success:function() {
        $('#result').show();
    }
});


</script>



<form id="test_form" method="" action="test1.php">
<input type="submit" id="sub" value="sub_value">
</form>

<div id="result"></div>

-------test1.php---------------------------------------


<?
$t="test value";
$u="test value 1";

?>

由于 让

1 个答案:

答案 0 :(得分:0)

Hy Jean

欢迎使用Stackoverflow

这是固定代码:

-------test.php-----------------------------------------

<script language="javascript" type="text/javascript">
$.post("test.php", {testval: val}, function(data){
   if (data.length>0){ 
 $('#result').show();
     $("#result").html(data); 
   } 
  }) 


</script>



<form id="test_form" method="" action="test1.php">
<input type="submit" id="sub" value="sub_value" name="testval">
</form>

<div id="result"></div>

-------test1.php---------------------------------------


<?
// now coding in PHP is easiyer
if(isset($POST["testval"]))
{
// this is now for your Learning purposes that you see how things are 
$testval = strip_tags(mysql_escape_string($POST["testval"]));
echo $testval;
}
// thats it have fun :-)
?>