/    Sign up×
Community /Pin to ProfileBookmark

How to make HTTP request in Jquery using things network payload?

Hi Team

I came to look for your help to this issue, basically i have HTML code and Jquery code to turn button on and off. It does well, But i am struggling to make HTTP integration of things network to send data back to it. Who can help me, here is my code below;

“`
<!—–Toggle switch button On/Off.
—>
<div class = “wrapper” align = “center”>
<div class=”btn-group” id=”toggle_event_editing”>
<button type=”button” class=”btn btn-danger locked_active”>OFF</button>
<button type=”button” class=”btn btn-success unlocked_inactive”>ON</button>
</div>
<div class=”alert alert-danger” id=”switch_status”>Switched off.</div>
</div>
// button for switch functionality on/off.
$(document).ready(function() {
$(‘#toggle_event_editing button’).click(function(){
if($(this).hasClass(‘locked_active’)) {
$(‘#switch_status’).html(‘Switched off’);
var makers = [{“dev_id”:”mkr1300″, “payload_raw”:”AAA”}];
$.ajax({
url:’https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/acts083_test/mkr1300?key=ttn-account-v2.7Ph6lBffU7wI9cLY5ljIhIb_I7sqH5EVvo5zs9uVyA0′,
type:’POST’,
data:JSON.stringify({Makers:makers}),
contentType: “application/json; charset=utf-8″,
dataType:”json”,
success:function(response){
alert(response);
},
error:function() {
$(‘#error’).text(“There was an error while processing your request. Please try again”);
}
});

}else{
$(‘#switch_status’).html(‘Switched on.’);
var makers = [{“dev_id”:”mkr1300″, “payload_raw”: “AAE”}];
$.ajax({
url:’https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/acts083_test/mkr1300?key=ttn-account-v2.7Ph6lBffU7wI9cLY5ljIhIb_I7sqH5EVvo5zs9uVyA0′,
type:’POST’,
data:JSON.stringify({Makers:makers}),
contentType:”application/json; charset=utf-8″,
dataType:”json”,
success:function(response) {
alert(response);
},
error:function() {
$(‘#error’).text(“There was an error while processing your request.Please try again”);
}
});
}
});
});
“`

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumDec 13.2019 — What do you mean when writing

"But i am struggling to make HTTP integration of things network to send data back to it."

Does your Ajax request fail?

When I open the URL in my browser I get error 405.
Copy linkTweet thisAlerts:
@TaGcobsauthorDec 13.2019 — Yes that is correct, i also get that. Please help
×

Success!

Help @TaGcobs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...