Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.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 如何识别对同一页面的ajax调用_Javascript_Ajax_Jquery - Fatal编程技术网

Javascript 如何识别对同一页面的ajax调用

Javascript 如何识别对同一页面的ajax调用,javascript,ajax,jquery,Javascript,Ajax,Jquery,})) 通过使用这个jquery,我调用了同一个页面“listdetails.php”(即:这个jquery在listdetails.php中)。这是我在页面开头输入的代码 $(document).ready(function(){ var temp='getUser'; $.ajax ({ type:'GET'; url: 'listdetails.php?ud=temp'; su

}))

通过使用这个jquery,我调用了同一个页面“listdetails.php”(即:这个jquery在listdetails.php中)。这是我在页面开头输入的代码

$(document).ready(function(){
    var temp='getUser';
    $.ajax ({
                type:'GET';
                url: 'listdetails.php?ud=temp';

                success:function(data)
                        {
                            alert(data);
                        }

           });
当我加载页面时,它会显示错误“注意:第8行C:\wamp\www\listdetails.php中的未定义索引:ud”

ie:变量ud未定义。如何避免此错误。我认为,如果只在页面请求为ajax时才需要检查条件,是否可以检查页面请求为ajax?

使用
isset

if($_GET['ud'] =="getUser")
{

    echo "ok";
}
要专门检查AJAX请求,请尝试

if(isset($\u服务器['HTTP\u X\u请求的\u带有'])和&strtolower($\u服务器['HTTP\u X\u请求的\u带有'])=='xmlhttprequest')


但是HTTP头很容易被欺骗。

如果ajax的url没有正确创建,您肯定不会进入$u get bcoz的if循环。我已经写了下面的代码,请检查它

if(isset($_GET['ud']) && $_GET['ud'] =="getUser")
{

    echo "ok";
}

如何检查页面请求是否为ajax没有万无一失的方法。如果将
?ud=temp
添加到所有AJAX请求中,上述方法就足够了。
var temp='getUser';
$.ajax ({
        type:'GET',
        url: 'listdetails.php?ud='+temp, // your code --- url: 'listdetails.php?ud=temp';

        success:function(data)
        {
              alert(data);
        }

});