我可以使用jQuery来执行$ _GET方法/查看文件的URL [英] Can I use jQuery to do $_GET method/look at file's url

查看:87
本文介绍了我可以使用jQuery来执行$ _GET方法/查看文件的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

在JavaScript中获取查询字符串值


我是编写一个使用Ajax远程保存项目的jQuery函数。我希望能够从我的函数的url中获取 edit.php?id = ###& field = ### info。我怎么做到这一点?

解决方案

你不需要jQuery来完成这项任务,你可以简单地用javascript来完成:

  function gup(name)
{
name = name.replace(/ [\ [] / ,\\\[)。更换(/[\]]/,\\\]);
var regexS =[\\?&]+ name +=([^&#] *);
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return;
else
返回结果[1];
}

然后,如果您检索此网址: http://www.yoursite.com/Index.php?g=12&param=43
来检索'param'参数,所有你需要做的就是:

pre $ var $ param_value = gup('param );

或'g'参数如下:

  var param_value = gup('g'); 

或者用您需要的参数名称切换'param'。


Possible Duplicate:
Get query string values in JavaScript

I am writing a jQuery function that saves an item remotely with Ajax. I'd like to be able to grab the edit.php?id=###&field=### info from the url right in my function. How would I do that?

解决方案

You don't need jQuery for this task, you can do it simply with javascript :

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
     return "";
  else
    return results[1];
}

Then if you retrieve this url : http://www.yoursite.com/Index.php?g=12&param=43 to retrieve the 'param' parameter, all you need to do is this :

var param_value = gup('param');

or the 'g' parameter like this :

var param_value = gup('g');

or switch 'param' with the name of the parameter you need.

这篇关于我可以使用jQuery来执行$ _GET方法/查看文件的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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