[英]javascript redirection only on second try
I wrote a little "webpage" to start streams on my xbmc with jsonrpc. 我写了一些“网页”以使用jsonrpc在我的xbmc上启动流。 Now the problem I am facing is that i always have to send the form request twice to make it work. 现在我面临的问题是,我总是必须发送两次表单请求才能使其正常工作。 could it be that I am using the window.open function wrong? 可能是我使用window.open函数错误吗? or am I missing something? 还是我错过了什么?
<html>
<body>
<head>
<script type="text/javascript">
function postFunction() { // inside script tags
var vForm = document.getElementById("frmGui");
var vStrServer = "";
var vStrFile = "";
var vStrPost = "http://";
vStrServer = vForm.idServer.value;
vStrFile = vForm.idFile.value;
vStrPost += vStrServer+"/jsonrpc?request={\"jsonrpc\":\"2.0\", ";
vStrPost += "\"id\":0, \"method\": \"Player.Open\", \"params\":{\"item\""
vStrPost += ":{\"file\":\""+vStrFile+"\"}}}";
window.open(vStrPost,"_self");
}
</script>
</head>
<table>
<tr>
<form id="frmGui" name="gui" action="#" onSubmit="postFunction(this)" methode="POST">
<td><input id="idServer" name="server" type="text" value="IP_ADRESS"/></td>
</tr>
<tr>
<td><input id="idFile" name="file" type="text"/></td>
</tr>
<tr>
<td><input type="submit"/></td>
</tr>
</form>
</table>
</body>
</html>
Try to put it into window.onload(cb). 尝试将其放入window.onload(cb)。
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onload https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onload
Why you passed argument whene you call postFunction()
? 为什么在调用postFunction()
传递参数? it has not argument upon decliration right way is 它没有争论正确的方法是
<form id="frmGui" name="gui" action="#" onSubmit="postFunction()" methode="POST">
remove this inside postFunction
brace 在postFunction
大括号内删除此
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.