简体   繁体   English

获取AJAX值并存储在php变量中

[英]Get AJAX value and Store in a php variable

how do I get this ajax value #name and store it in a php variable? 如何获取此ajax值#name并将其存储在php变量中? what i have done is put it in a HTML. 我所做的是将其放入HTML中。

<p id="name"></p>


    setInterval(function(){

    $.ajax({
        url:"count.php", 
        type:"GET", 
        async:true, 
        cache:false, 
        success:function(count)
        {
            $("#name").html(count);

        }
    });

},1000);

Use data to pass the variable to server. 使用data将变量传递给服务器。 ie to count.php 即count.php

 <p id="name"></p>
        setInterval(function(){
        var name=$("#name").val();
        $.ajax({
            url:"count.php",
            data:{name:name}, 
            type:"GET", 
            async:true, 
            cache:false, 
            success:function(count)
            {
               var res = $.parseJSON(count);
               var result= res.name;
               $("#name").html(result);
            }
        });

    },1000);

And in count.php 并在count.php中

   $name=$_GET['name'];
   echo json_encode(array('status'=>TRUE,'name'=>$name));die;

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

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