简体   繁体   English

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

[英]Passing two values for ajaxForm(), using jQuery and PHP

I want to pass both the values using ajaxForm, displaying both the values separately in test.php 我想使用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";

?>

Thanks Jean 谢谢让

Hy Jean 海兰吉恩

Welcome to Stackoverflow 欢迎来到Stackoverflow

Here is the fixed code: 这是固定代码:

-------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 :-)
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM