【发布时间】:2014-01-26 07:41:47
【问题描述】:
我正在使用 post 方法传递变量,但无法传递变量的完整值。
这是脚本:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var problem_code = $("#problem_code").val();
var code = $("#code").val();
var lang = $("#lang").val();
$.ajax({
type: "POST",
url: "ajax.php",
cache:false,
data : {problem_code:problem_code,code:code,lang:lang},
success: function(html)
{
//alert("ajax response returned.. ");
//console.log(html);
$(".show-result").empty();
$(".show-result").append('<br>' + html);
}
})
});
</script>
这是剩下的部分
<?php
$code=stripcslashes($_POST['code']);
$lang=stripcslashes($_POST['lang']);
?>
通过另一个文件“Submit.php”获取$code和$lang值
现在使用输入隐藏字段
<input type="hidden" id="problem_code" name="problem_code" value=<?php echo $problem_code;?> >
<input type="hidden" id="code" name="code" value=<?php echo ($code);?> >
<input type="hidden" id="lang" name="lang" value=<?php echo $lang;?> >
但在使用隐藏字段传递 $code 值时,它会显示意外行为。
这是运行上述脚本时的查看源代码示例
<input type="hidden" id="problem_code" name="problem_code" value=LUCPAL >
<input type="hidden" id="code" name="code" value=#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main() {
int t;
scanf("%d",&t);
while(t--)
{
long long int A,B,copy,sum=0;
scanf("%lld %lld",&A,&B);
copy=B;
int digit=0;
while(copy>0)
{
digit++;
copy=copy/10;
}
while(digit--)
{
sum=10*sum+9;
}
long long int sum2=sum/2,diffA,diffB;
if(sum2>=A && sum2<=B)
{
printf("%lld
",(sum2)*(sum2+1));
}
else
{
diffA=fabs(sum2-A);
diffB=fabs(sum2-B);
if(diffA<diffB)
printf("%lld
",A*(sum-A));
else
printf("%lld
",B*(sum-B));
}
}
// your code goes here
return 0;
}
>
<input type="hidden" id="lang" name="lang" value=11 >
`
printf("%lld\n",A*(sum-A) become printf("%lld
",A*(sum-A));
并且只有 '#include' 从所有代码中传入 ajax.php。
【问题讨论】:
-
你知道你应该在你的 jquery 开启器中使用
-
没有@AndrewAllenWest 我应该只使用
-
什么意外行为?
-
@AndrewAllenWest:这仅适用于 HTML5 - XHTML 是正确的语法,也许我遗漏了一些东西,但我没有看到任何关于版本的提及
-
@KundanSinghChouhan 当我在文件中打印 $code 的值时,它正在打印通过表单传递的正确代码,但在通过输入隐藏字段传递给 ajax.php 时,只有“#include
”,其余的代码没了?
标签: php jquery ajax forms post