Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php AJAX中的POST方法_Php_Jquery_Ajax_Forms_Post - Fatal编程技术网

Php AJAX中的POST方法

Php AJAX中的POST方法,php,jquery,ajax,forms,post,Php,Jquery,Ajax,Forms,Post,我使用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 = $(

我使用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>

$(文档).ready(函数(){
var problem_code=$(“#problem_code”).val();
var代码=$(“#代码”).val();
var lang=$(“#lang”).val();
$.ajax({
类型:“POST”,
url:“ajax.php”,
cache:false,
数据:{问题代码:问题代码,代码:代码,lang:lang},
成功:函数(html)
{
//警报(“返回ajax响应…”;
//log(html);
$(“.show result”).empty();
$(“.show result”).append(“
”+html); } }) });
这是剩下的部分

<?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;?> >
>

将所有替换为
(无论如何,在value=“…”部分) post请求将认为您错误地关闭了标记,并在第一个>(小于)符号处被切断。 编辑: 像这样:

<input type="hidden" id="problem_code" name="problem_code" value=LUCPAL >
<input type="hidden" id="code" name="code" value='#include &gt;iostream&lt;
#include&gt;stdio.h&lt;
#include&gt;math.h&lt;
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&lt;0)
    {
        digit++;
        copy=copy/10;
    }
    while(digit--)
    {
        sum=10*sum+9;
    }
    long long int sum2=sum/2,diffA,diffB;
    if(sum2&lt;=A && sum2&gt;=B)
    {
        printf("%lld
",(sum2)*(sum2+1));
    }
    else
    {
        diffA=fabs(sum2-A);
        diffB=fabs(sum2-B);
        if(diffA&gt;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));

`
printf(“%lld\n”,A*(和-A)变成printf(“%lld”)
“,A*(总和A));

你知道你应该在jquery的开场白中使用反对吗?不@AndrewAllenWest我应该使用onlye而不是什么意外的行为吗?@AndrewAllenWest:这只适用于HTML5-XHTML,语法是正确的,也许我遗漏了一些东西,但我看不到有提到什么version@KundanSinghChouhan当我打印的价值$code在文件中它正在打印通过表单传递的正确代码,但在通过输入隐藏字段传递到ajax.php时仅“include”剩下的代码都到哪里去了?你的意思是我应该用源代码转换所有的<>对吗?还有关于新行字符的什么?只有在值部分-新行应该可以,我注意到iostream>关闭
<input type="hidden" id="problem_code" name="problem_code" value=LUCPAL >
<input type="hidden" id="code" name="code" value='#include &gt;iostream&lt;
#include&gt;stdio.h&lt;
#include&gt;math.h&lt;
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&lt;0)
    {
        digit++;
        copy=copy/10;
    }
    while(digit--)
    {
        sum=10*sum+9;
    }
    long long int sum2=sum/2,diffA,diffB;
    if(sum2&lt;=A && sum2&gt;=B)
    {
        printf("%lld
",(sum2)*(sum2+1));
    }
    else
    {
        diffA=fabs(sum2-A);
        diffB=fabs(sum2-B);
        if(diffA&gt;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));