Ajax Jquery Script

Hi,

Is it possible to create Jquery ajax script to obtain information from the Vera ?

I tried locally, remotely, but I get errors.

is what it is implemented? is it going to be implemented?

thx.

Yeah, AJAX works, definitely. I use it in my Caddx alarm plugin for the information tabs. You only have to be aware of the usual restrictions on cross-site JavaScript.

What are you trying to do, specifically?

I try to make an Ajax request to get the status of my vera


$.ajax({
  url: "http://vera.mydomain.com/data_request?id=status&output_format=json",
  contenttype:'json',
  success: function(html){
   alert(html);
  }
});

If I run the query in firefox adress bar it works
but if I run in an Ajax request it crashes

Firebug send : “NetworkError: 400 Bad Request - http://vera.mydomain.com/data_request?id=status&output_format=json

ps: on my server I have a reverse proxy that redirects vera.mydomai.com to ipadress:80 of my vera

thank you for your help
… and sorry for my English (i m french)

Assuming you are using jQuery (there are many AJAX frameworks). Also assuming that you are using port 3480 (http://vera.mydomain.com:3480/data_request?id=status&output_format=json) in your request.

Things to check:

  • In the browser bar you are using HTTP GET. It’s possible that you are accidentally telling your AJAX framework to use HTTP POST.
  • jQuery docs suggest you might have to pass id and output_format with the AJAX “data” field, not on the URL. (I am not an expert on jQuery; I have used Prototype more, and Prototype needed this.)
  • Vera sets the MIME type of the response wrong. You might have to force it to JSON with the AJAX “dataType” field.

Use an HTTP analysis tool like Firebug to see what you are really sending to Vera. It can be very fussy.

hello,

thank you for your response.

I have 401 Unauthorized in firebug when i try it.

Would you have an example of a query ajax that works with your vera?

thank you

[quote=“elkamy, post:5, topic:170027”]I have 401 Unauthorized in firebug when i try it.
Would you have an example of a query ajax that works with your vera?[/quote]

It’s built into a much larger program.

Stick with local testing. I and others get very mixed results when testing through the cp.mios.com gateway.

I tried your code but i have 401 unautorized… Locally :frowning:

Post your code and I will see how it behaves on my system.

Edit: thanks, got it. It will be several hours before I can look at it.

[code]

[/code]

Ok Thanks
That’s good, in France it is 11:00 p.m. ;D

I can make it work and get a 200 OK, but only if I host the ajax.html file on the Vera itself. Otherwise, yes, I get a 400 Bad Request.

I mentioned cross-domain queries and that they don’t work. Please confirm that you’re putting the ajax.html file on the Vera (or that you’ve done some advanced proxying that has the same effect).

401 Unauthorized, you got? You haven’t enabled “local authentication” on the Vera, have you? I think that you need to describe more carefully how you have things set up, because buried in there is the reason why it works for me and not for you.

Hi,
I have enabled local authentication but i dont Know How to disable it…

I not find option in Vera ui …


I am here: Google Maps

I think you have to do it from the cp.mios.com portal.

But it does raise a good question: how do you do Ajax with local authentication turned on? No idea yet.