Using jQuery to read JSON from Ardunio Yun REST API (Bridge) -
i have arduino yun , trying read state of pin (high or low) using rest api provided bridge library.
i have in arduino sketch, trying return state of pin in json.
client.println("content-type: application/javascript"); client.println(); //mandatory blank line client.print("{\"state\":\"1\"}"); then have jquery running on local server (same lan yun).
$.ajax({ type: "get", url: "http://192.168.1.80/arduino/digital/13/", datatype: 'jsonp', success: function(resp){ alert(resp.state); }, error: function(e){ alert(e); } }); http://192.168.1.80/arduino/digital/13/ rest endpoint status of pin (pin 13 in case). when use browser go http://192.168.1.80/arduino/digital/13/, browser displays:
{"state":"1"} however, when run ajax call in browser, "[object object]" in alert.
i created test.html has:
{"state":"1"} written in plaintext, no html or script tags, , when change ajax call url 192.168.1.80... test.html, works , "1" i'm looking in alert.
it seems i'm not getting proper json written client arduino, can't figure out.
thanks help!
Comments
Post a Comment