Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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
Javascript ajaxphp在执行少量动态操作后发送和返回文本_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript ajaxphp在执行少量动态操作后发送和返回文本

Javascript ajaxphp在执行少量动态操作后发送和返回文本,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我想动态地将textarea的文本发送到PHP变量中,在PHP中对文本执行一些操作,并动态地返回结果 目前,我正在努力快速恢复PHP变量,但之前我不知道如何将textarea的文本快速发送到PHP中 我有这个密码 <html> <head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, initial-scale=1.0'>

我想动态地将textarea的文本发送到PHP变量中,在PHP中对文本执行一些操作,并动态地返回结果

目前,我正在努力快速恢复PHP变量,但之前我不知道如何将textarea的文本快速发送到PHP中

我有这个密码

<html>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <script src='http://code.jquery.com/jquery.js'></script>
</head>
<body>
<textarea name="text"></textarea><br />
<script type="text/javascript">
    $(document).ready(function() {
        setInterval('get_counter()', 500);
    });
    function get_counter()
    {
        $('.result').load('2.php');
    }
</script>
<div class="result"></div>
</body>
</html>


$(文档).ready(函数(){ setInterval('get_counter()',500); }); 函数get_counter() { $('.result').load('2.php'); }
这是2.php

<?php
if (isset($_POST['text'])) {
    $text = $_POST['text'];
}

如果参数作为对象传递,则可以通过函数中的第二个参数将参数传递给后端,并发出POST请求

<script type="text/javascript">
    $(document).ready(function() {
        setInterval(get_counter, 500);
    });
    function get_counter()
    {
        $('.result').load('2.php',{text:$('textarea').val()});
    }
</script>

$(文档).ready(函数(){
设置间隔(获取计数器,500);
});
函数get_counter()
{
$('.result').load('2.php',{text:$('textarea').val()});
}