JavaScript通过表单值获取请求

JavaScript通过表单值获取请求

问题描述:

有问题了解如何创建GET请求到另一个获取该网站html内容的域。表单数据是使用的获取请求的一部分。JavaScript通过表单值获取请求

<form name="login"> 
    <div class="login"> 

    <input type="text" placeholder="User Name" name="userid"><br> 
    <input type="password" placeholder="Password" name="pswrd"><br> 
    <input type="fromdate" placeholder="From date" name="startdate"><br> 
    <input type="Todate" placeholder="To Date" name="todaysdate"><br> 
    <input type="button" onclick="check(this.form)" value="Check Data Usage"/> 

    </div> 

function check(form) 
{ 
    var request = new Request({ 
    url: '"http://dashboard.somesite.io/DashboardDataServices.asmx/GetMyUsage?userName="+form.userid.value+"&password="+form.userid.value+"&fromDate="+form.startdate.value+"&toDate="+form.todaysdate.value' 
method: 'GET' 
    }); 
    fetch(request); 
}; 

我得到的常见的问题:

Uncaught ReferenceError: check is not defined at HTMLInputElement.onclick

+1

之间的JavaScript代码参见本:https://developer.mozilla.org/en-US/docs/Web/API/Request –

+0

函数'check'放在HTML中或者使用'

+0

它放在表单元素之后的主体中。 – D0USMOKEHAZE

你已经关闭了你的股利,但您的窗体仍无法与</form>标签关闭。 你甚至可以调用的onsubmit功能标签是这样的:

<form onsubmit="yourfunction()"> 
<input type="submit" value="submit"> 
</form> 

<script></script>

<script> 
function check(form) 
{ 
    var request = new Request({ 
    url: '"http://dashboard.somesite.io/DashboardDataServices.asmx/GetMyUsage?userName="+form.userid.value+"&password="+form.userid.value+"&fromDate="+form.startdate.value+"&toDate="+form.todaysdate.value' 
method: 'GET' 
    }); 
    fetch(request); 
}; 
</script>