我無法弄清楚這一點,我問過幾個人,我們很難過。我通常不會使用AJAX,但我覺得我必須在這種情況下。我如何通過AJAX將此信息發送到POST
難道別人我會用這個嗎?
<!DOCTYPE>
<html>
<body>
<center>
<br>
<br>
<br>
<form>
Tell your device what to do!<br>
<br>
<input type="radio" name="arg" value="on">Turn the LED on.</input>
<br>
<input type="radio" name="arg" value="off">Turn the LED off.</input>
<br>
<input type="radio" name="arg" value="blueSwap">Toggle Blue.</input>
<br>
<input type="radio" name="arg" value="allSwap">Toggle All.</input>
<br>
<br>
<input type="submit" value="Do it!"/>
</form>
<br>
</center>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script>
let url = 'https://api.particle.io/v1/devices/2f0021000547353138383138/led?access_token=150a347fb4277975913f5dfe24e2fb739171b3c5'
$('form').on('submit', (e) => {
e.preventDefault()
let data = $(this).serialize()
$.ajax({
url: url,
type: 'POST',
data: data
}).done(() => {
console.log('sent')
})
})
</script>
</body>
</html>
這是一個成形差的問題。有關建議請參閱:http://stackoverflow.com/help/how-to-ask –
什麼是問題?在所有情況下done()被調用。 –