Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用onsubmit事件获取查询字符串_Javascript_Ajax_Onsubmit - Fatal编程技术网

Javascript 使用onsubmit事件获取查询字符串

Javascript 使用onsubmit事件获取查询字符串,javascript,ajax,onsubmit,Javascript,Ajax,Onsubmit,我想将表单提交转换为ajax请求。这是我的密码: <html> <head> <meta charset="iso8859-9"> <script> document.addEventListener("DOMContentLoaded", function(event) { document.getElementById("query_form").onsubmit = function(event) { cons

我想将表单提交转换为ajax请求。这是我的密码:

<html>
<head>
<meta charset="iso8859-9">
<script>

  document.addEventListener("DOMContentLoaded", function(event) {

    document.getElementById("query_form").onsubmit = function(event) {
        console.log(event);
        return false;
    }
  });
</script>
</head>

<body>
<form action="query.php" id="query_form" method="get">
<input name="first">
<input name="second">
<button type="submit">
</form>
<table id="results"></table>
</body>
</html>

document.addEventListener(“DOMContentLoaded”),函数(事件){
document.getElementById(“查询表单”).onsubmit=函数(事件){
console.log(事件);
返回false;
}
});
我可以在onsubmit事件中读取计算出的查询字符串,将其用于ajax,还是需要自己使用javascript创建它。如果可能的话,我不想使用外部库

我可以在onsubmit事件中读取计算出的查询字符串以将其与ajax一起使用吗

没有

我需要自己使用javascript创建它吗

一般解决方案包括在event.target.elements、集合名称/值对上循环,同时过滤掉字段集、禁用的元素、未选中的复选框/单选按钮,正确处理多个选择,然后通过
encodeURIComponent(name)+“=”+encodeURIComponent(value)传递所有结果
加入之前,请在
上加入

我可以在onsubmit事件中读取计算出的查询字符串以将其与ajax一起使用吗

没有

我需要自己使用javascript创建它吗

一般解决方案包括在event.target.elements、集合名称/值对上循环,同时过滤掉字段集、禁用的元素、未选中的复选框/单选按钮,正确处理多个选择,然后通过
encodeURIComponent(name)+“=”+encodeURIComponent(value)传递所有结果
加入之前,请在
上加入