使用Jquery获取当前URL [英] Getting current URL using Jquery

查看:106
本文介绍了使用Jquery获取当前URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在javascript和jquery中是非常新的.

I am very new in javascript and jquery.

$.getJSON("idcheck.php?callback=?", { url:  /*i want full url to be print*/ }, function(json){
  //alert(json.message);
});

如何在上面的url之后获取页面上的当前完整URL?

How do i get current full url on page on after url: in above?

谢谢

推荐答案

这将为您提供当前的网址:

This will give you the current url:

window.location.pathname

$.getJSON("idcheck.php?callback=?", { url:  window.location.pathname }, function(json){
  //alert(json.message);
});

使用PHP(可通过通过找到)

edit 2: Using PHP (found via)

<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>


$.getJSON("idcheck.php?callback=?", { url:  "<?php echo curPageURL(); ?>" }, function(json){
  //alert(json.message);
});

这篇关于使用Jquery获取当前URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆