我正在尝试将浏览器定向到其他页面.如果我想要一个GET请求,我可能会说
document.location.href = 'http://example.com/q=a';
Run Code Online (Sandbox Code Playgroud)
但是我试图访问的资源不会正常响应,除非我使用POST请求.如果这不是动态生成的,我可能会使用HTML
<form action="http://example.com/" method="POST">
<input type="hidden" name="q" value="a">
</form>
Run Code Online (Sandbox Code Playgroud)
然后我只需从DOM提交表单.
但实际上我想要允许我说的JavaScript代码
post_to_url('http://example.com/', {'q':'a'});
Run Code Online (Sandbox Code Playgroud)
什么是最好的跨浏览器实现?
编辑
对不起,我不清楚.我需要一个改变浏览器位置的解决方案,就像提交表单一样.如果使用XMLHttpRequest可以实现这一点,那就不明显了.这不应该是异步的,也不应该使用XML,所以Ajax不是答案.
基本上我有一个index.html如下所示..
<html>
<head>
<title>UI Test: Main Menu</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="general.js"></script>
</head>
<body>
<input type="button" value="Details" onclick="javascript:$('#mainContainer').load('loadpage.html #name1div *');"/><br>
<div id="mainContainer">
</div>
Run Code Online (Sandbox Code Playgroud)
loadpage.html cotaints
<div id="nav1div><h3>1 DIV </h3> </div>
<div id="nav2div><h3>2 DIV </h3> </div>
<div id="nav3div><h3>3 DIV </h3> </div>
<div id="nav4div><h3>4 DIV </h3> </div>
Run Code Online (Sandbox Code Playgroud)
我的目标是基本上将一个div一次加载到主容器中,我知道加载函数可以立即加载整页但这不是我需要做的.
有几个看看类似的问题,但似乎无法解决这个问题..
感谢所有人的帮助!