put the javascript code directly in the HTML page, it does work.(将JavaScript代码直接放在HTML页面中,即可正常工作。)
Howcome it does not work if I reference the script using the src attribute on the script This is my HTML page:(如果我使用脚本上的src属性引用该脚本,它将无法正常工作,这是我的HTML页面:)
<html>
<head></head>
<body>
<script src="file.js"></script>
</body>
</html>
I can not get the following javascript code to send data to a PHP page: this is inside file.js(我无法获得以下javascript代码来将数据发送到PHP页面:这位于file.js内部)
var http = new XMLHttpRequest();
var url = 'server.php';
var params = 'a=use&b=12345678';
http.open('POST', url, true); // error javascript stop always here
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200)
{ alert(http.responseText); } }
http.send(params);
and this is inside server.php
:(这是在server.php
内部:)
<?php
$username = $_POST['a'];
$password = $_POST['b'];
echo 'username :' . $username;
?>
When I put the javascript code directly in the HTML page, it does work.(当我将javascript代码直接放在HTML页面中时,它确实起作用。)
Howcome it does not work if I reference the script using the src
attribute on the script
tag?(如果我使用script
标记上的src
属性引用脚本,怎么办?) for example when i put the file.js script in online compiler like 'playcode.io' it does not work(例如,当我将file.js脚本放在“ playcode.io”之类的在线编译器中时,它不起作用)
ask by MYARCH translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…