简体   繁体   中英

JavaScript get requests with form value

Having issues figure out how to create a GET request to another domain which gets that website html content. The Form Data is part of the get requests which is used.

<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);
};

I get usual problems:

Uncaught ReferenceError: check is not defined at HTMLInputElement.onclick

put your javascript code between <script> and </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>

You have closed your div but your form is still not closed with </form> tag. You can even call an onSubmit function in tag like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM