weixin_33693070 2012-08-06 10:50 采纳率: 0%
浏览 23

Ajax调用子域到域

I have some troubles with ajax cross-scripting request using jquery. I'm in a subdomain named test.example.com and i'm doing a ajax call to www.example.com/action like this :

$.ajax({ 
url:"http://www.example.com/action",
type:"post", 
crossDomain:true,
dataType:"jsonp",
jsonp:"cross_domain_action",
xhrFields:{withCredentials:true},
success:function(data){}
});

The problem is that i dont know how to test if the request is an ajax one or not in www.example.com/action.

I'm using CakePHP 1.3 and there is a component call "request_handler.php" with the function

function isAjax() {
    return env('HTTP_X_REQUESTED_WITH') === "XMLHttpRequest";
}

I found that there is not that HTTP header in the request.

X-Requested-With    XMLHttpRequest

If you have any ideas :) Thanks

  • 写回答

2条回答 默认 最新

  • ℡Wang Yan 2012-08-06 11:05
    关注

    Well that's exactly what you use to test if it's and ajax request. I usually use:

    if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) 
    && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') 
    {//this is an ajax request}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器