简体   繁体   English

jQuery ajax请求同一页面PHP无法执行

[英]jQuery ajax request same page PHP doesnt execute

I am trying to send a variable in a request to the same page and then check if the variable is set. 我正在尝试将请求中的变量发送到同一页面,然后检查该变量是否已设置。

 $.ajax({
            url: "index.php",
            type: "POST",
            data:  {idss:idss},
            success: function(data){
                console.log("hello");
            }
        }); 

if(isset($_POST['idss'])){
    echo "Set";
}

However, when this runs I only see "hello" in the console and yet I dont see the output of 'echo' on the page. 但是,当它运行时,我在控制台中仅看到“ hello”,而在页面上却看不到“ echo”的输出。

Am I doing something wrong? 难道我做错了什么?

The POST data is being sent to the page in your ajax request, not your current page. POST数据将发送到您的Ajax请求中的页面,而不是当前页面。 index.php would have that POST data set. index.php将具有该POST数据集。

   $.ajax({
            url: "index.php",
            type: "POST",
            data:  {idss:idss},
            success: function(data){
                console.log("hello");
                $('#here').html(data['whatever_you_returned']);
            }
        }); 

   <div id="here"></div>

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

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