Quantcast
Channel: ThingSpeak IoT Community - All Forums
Viewing all articles
Browse latest Browse all 1833

Vinod on I do not want return page after api/update ...

$
0
0

Here's a simple example you can expand on:

<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Test Page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
function postIt(){
var valueToPost = $('#field1').val();
var formData = {api_key:"YOURAPIKEYHERE",field1:valueToPost};
$.ajax({url : "https://api.thingspeak.com/update",
type: "POST",
data : formData,
success: function(data, textStatus, jqXHR){ if (data==="0") {alert("Channel not updated");} else {alert("New entry " + data + " added to channel");}},
error: function (jqXHR, textStatus, errorThrown) { alert("Error posting data");}
});
};
</script>

</head>
<body>
<h1>Example HTML page
<form action="" method="get">
<p>
<label>Desired Temperature: </label>
<input id ="field1" type="text" value=""><br><br>
<input value="Update ThingSpeak" type="button" onClick=postIt()>
</p>
</form>
</h1>
</body>
</html>

You can remove the alert()'s if you don't want the page to display alerts. If this is confusing you may want to take some basic javascript classes.


Viewing all articles
Browse latest Browse all 1833

Trending Articles