可能重复:
使用jQuery获取查询字符串
如何使用jQuery将查询字符串的值获取到文本框中?
让我们说网址是http://intranet/page1.php?q =你好
我希望"你好"在文本框中.
我似乎无法找到有关getParameterByName()的任何详细文档.我搜索了Mozilla,谷歌和这里.我错过了什么吗?
我想在网址中的问号后得到所有内容.我已经看到了一种方法,它不需要一个功能,但在我的生活中找不到它.
网址
fsdhfbsdfj/index.html?hello
Run Code Online (Sandbox Code Playgroud)
得到
hello
Run Code Online (Sandbox Code Playgroud) 可能重复:
在JavaScript中获取查询字符串值
如何在javascript中获取get变量?
我想在jquery函数中传递它.
function updateTabs(){
//var number=$_GET['number']; how can i do this?
alert(number);
$( "#tabs" ).tabs({ selected: number });
}
Run Code Online (Sandbox Code Playgroud) 我有一个使用get方法并包含一个数组的表单:
http://www.example.com?name[]=hello&name[]=world
我正在尝试使用JavaScript或jQuery检索数组值'hello'和'world'.
我已经看过Stack Overflow上的类似解决方案(例如,如何在JavaScript中获取查询字符串值?)但它们似乎只处理参数而不是数组.
是否有可能获得数组值?
这是login.html的代码:
<ul>
<li class="introduction">
<a href="introduction.html">
<span class="icon"></span>
Introduction
</a>
</li>
<li class="login active">
<a href="#">
<span class="login"></span>
Login
</a>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
外部链接将首先使用我想要保留的一些查询参数进入当前页面(登录).如果用户点击第一个链接introduction,则会加载introduction.html.但是,前一页(登录)的所有查询参数都将丢失.
无论如何我可以在保持查询参数的同时加载此页面吗?使用HTML或Javascript.
非常感谢.
$httpBackend.whenGET('/restpath/api/v1/books')
.respond({// some data});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
Error: Unexpected request: GET /restpath/api/v1/books
Expected GET /restpath/api/v1/books?limit=10&start=1
Run Code Online (Sandbox Code Playgroud)
对于expectGET,我有以下内容,这将创建动态查询字符串.主要是'start'参数和whenGET部分,我试图根据'start'服务器动态内容
$httpBackend.expectGET('/restpath/api/v1/books?limit=10&start=1');
// the actual service goes here , which does the $http service. we don't care
$httpBackend.flush();
我正在加注发票页面,用户可以在点击按钮时提出发票,我会拨打api电话,在收到回复后我想将一些数据发送到页面(RaisedInvoice.jsx),这应该是在新标签中打开,我该怎么做.我没有得到的是如何在单击ReactJs中的按钮时在新选项卡中打开页面.
RaiseInvoice.jsx:
import React from 'react';
import Links from './Links.jsx';
import history from './history.jsx';
import axios from 'axios';
class RaiseInvoice extends React.Component {
constructor(props) {
super(props);
// This binding is necessary to make `this` work in the callback
this.state = {projects: [], searchParam : ''};
this.raiseInvoiceClicked = this.raiseInvoiceClicked.bind(this);
}
raiseInvoiceClicked(){
// here i wish to write the code for opening the page in new tab.
}
render() {
return (
<div>
<Links activeTabName="tab2"></Links>
<div …Run Code Online (Sandbox Code Playgroud) 以下是一些网址:
http://sub.example.com/?feed=atom&hello=world
http://www.sub.example.com/?feed=atom&hello=world
http://sub.example.com/?hello=world&feed=atom
http://www.sub.example.com/?hello=world&feed=atom
http://www.sub.example.com/?hello=world&feed=atom
http://www.sub.example.com/?hello=world&feed=atom#123
Run Code Online (Sandbox Code Playgroud)
如您所见,它们都导致完全相同的页面,但URL格式不同.这是另外两个基本的例子:
http://example.com/hello/
http://example.com/hello
Run Code Online (Sandbox Code Playgroud)
两者都是一样的.
我想将 URL转换为一种标准格式,这样当我将URL存储在数据库中时,我可以轻松检查数据库中是否已存在URL字符串.
由于URL的格式化方式各不相同,这可能令人费解.
将URL转换为一种标准格式的最终方法是什么?也许parse_url()路线......?
正如评论中所述,没有明确的解决方案,但目标是尽可能接近我们所拥有的内容而不 "检索"页面.请在发布此赏金的答案之前阅读评论.
我已经使用 res.sendFile() 成功实现了提供静态文件,但是如果我添加一些查询字符串,它就不起作用。
例如,下面的代码工作得很好。
res.sendFile(path.join(__dirname, '../public', '/index.html'));
Run Code Online (Sandbox Code Playgroud)
但如果我这样做,它就会失败
res.sendFile(path.join(__dirname, '../public', '/index.html?id=' + req.params.id));
res.sendFile(path.join(__dirname, '../public', '/index.html?id=123'));
Run Code Online (Sandbox Code Playgroud)
然后我得到以下错误
ENOENT, stat '/Users/krishnandu/Documents/Project/public/index.html?id=123'
404
Error: ENOENT, stat '/Users/krishnandu/Documents/Project/public/index.html?id=123'
at Error (native)
Run Code Online (Sandbox Code Playgroud) javascript ×6
html ×2
query-string ×2
angularjs ×1
arrays ×1
express ×1
forms ×1
get ×1
httpbackend ×1
jquery ×1
node.js ×1
parameters ×1
php ×1
react-router ×1
reactjs ×1
static ×1
url ×1