hello friends,
i have an imp receiving data from an HTTP IN node. in order to push data into the node i first used an HTML form.
`
Value: `i stopped using this method because when i submited a string, the page was reloaded, but i got an “OK” so it was working.
in order to avoid this i tried to setup an jQuery ajax post so that i could handle the response and disable the page reload when the button was clicked. this is my code:
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> <script> $(function(){ $("#contact_form").submit(function(event){ event.preventDefault(); var command = $("input#command").val(); var send = 'value=' + command; $.ajax({ type: 'POST', url: 'https://api.electricimp.com/v1/_hidden_', data: send, success: function(response,status,object) { alert("sucess"); }, error: function(jqXHR, exception) { //alert(jqXHR.responseText); if (jqXHR.status === 0) { alert('Not connect.\ Verify Network.'); } else if (jqXHR.status == 404) { alert('Requested page not found. [404]'); } else if (jqXHR.status == 500) { alert('Internal Server Error [500].'); } else if (exception === 'parsererror') { alert('Requested JSON parse failed.'); } else if (exception === 'timeout') { alert('Time out error.'); } else if (exception === 'abort') { alert('Ajax request aborted.'); } else { alert('Uncaught Error.\ ' + jqXHR.responseText); } }, }); }); }); </script>
and in the body of my page i have the simple text input:
`
with this setup i CAN send the string to the imp, i know this i’ve tested it and the http in node receives the string. HOWEVER i’m not getting a sucess on the ajax post, instead, i’m getting inside the “error” function. in this function with my “if else” i found that i am always getting the STATUS = 0.
i’ve tryed searching for an explanation and this can occur if you send an ajax call and a refresh of the browser was trigger before getting the ajax response, the ajax would be cancelled and i would get this status. BUT in the beggining of my function with is handling the submit button i state: event.preventDefault();
i hope this is something simple that i am missing. and sorry to bring this up to you guys, but i’m not familiar with the language and i really can’t see what’s going on.
thanks in advance