alotaiba / FlyJSONP

FlyJSONP is a small JavaScript library, that allows you to do cross-domain GET and POST requests, with JSON response.
http://alotaiba.github.com/FlyJSONP
Other
161 stars 25 forks source link

Can't draw data from a RAILS service #1

Closed akxs14 closed 12 years ago

akxs14 commented 12 years ago

Hi to all,

I am trying to pull some json from a restfull RAILS app which is already feeding other clients but the success response is not triggered.

Among other things I tried with the following code:

    FlyJSONP.init({debug:true});
    var url = document.getElementById("txt").value;

    FlyJSONP.get({
      url: url,
      success: callBack,
      error: function (errorMsg) {
        console.log(errorMsg);
      },
      parameters: {
        username: 'user',
        password: 'pass',
        contentType: "application/json"            
      }
   });

And here's what I get back:

In console:

Initializing! flyjsonp.js:133Initialization options flyjsonp.js:133 Object flyjsonp.js:133Getting JSONP data ad_formats:-1Resource interpreted as Script but transferred with MIME type application/json.

And the headers:

Request URL:https://api.ffm.nugg.ad/ad_formats?username=demo&password=demonugg&contentType=application%2Fjson&callback=flyjsonp_851E4A080E7D4B9D9772559D3AC9F11B Request Method:GET Status Code:200 OK Request Headersview source Accept:/ Referer:http://dashboard.nuggad.dev/ie_test.html User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22 Query String Parametersview URL encoded username:demo password:demonugg contentType:application/json callback:flyjsonp_851E4A080E7D4B9D9772559D3AC9F11B Response Headersview source Cache-Control:must-revalidate, private, max-age=0 Connection:Keep-Alive Content-Type:application/json; charset=utf-8 Date:Thu, 22 Dec 2011 12:51:01 GMT Etag:"54f43d428fb532fd87397740b05f8fb1" Keep-Alive:timeout=15, max=99 Server:Apache/2.2.9 (Debian) Phusion_Passenger/3.0.9 mod_ssl/2.2.9 OpenSSL/0.9.8g Set-Cookie:_nuggad_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFRkkiJWZkNjVjMTJhNzAyOTQ5M2I2MWViZTEzMGY1YmQ5YmZhBjsAVEkiDHVzZXJfaWQGOwBGaUU%3D--2d89a4ee6ae3e7527c2315e45697c3b36e8aeca5; domain=.nugg.ad; path=/; HttpOnly Status:200 Transfer-Encoding:Identity X-Powered-By:Phusion Passenger (mod_rails/mod_rack) 3.0.9 X-Rack-Cache:miss X-Request-Id:f60fb62d2b0ad3335587c6f54eb77966 X-Runtime:0.009249 X-Ua-Compatible:IE=Edge,chrome=1

Thank in advance for any suggestion!

alotaiba commented 12 years ago

I'm unable to access your resource URL to test and validate the issue. You could test your api on the live demo: http://alotaiba.github.com/FlyJSONP/#!/demo

If you're still unable to fetch the JSON response, then please let me know and put your resource live so I can debug and see what I can do.

akxs14 commented 12 years ago

The resource is not exposed to internet, the public endpoints are under

https://api.nuggad.net/ad_formats

There is a demo account you can use for authentication:

user: demo pass: demonugg

I had a problem in the live demo as well. Is there a case that the demo did not respond because I did not specify the header type in it? (it is application/json).

2011/12/22 Abdulrahman Alotaiba < reply@reply.github.com

I'm unable to access your resource URL to test and validate the issue. You could test your api on the live demo: http://alotaiba.github.com/FlyJSONP/#!/demo

If you're still unable to fetch the JSON response, then please let me know and put your resource live so I can debug and see what I can do.


Reply to this email directly or view it on GitHub: https://github.com/alotaiba/FlyJSONP/issues/1#issuecomment-3253454

akxs14 commented 12 years ago

Thank you for your valuable time and assistance.

2011/12/26 Angelos Kapsimanis angelos.kapsimanis@gmail.com

The resource is not exposed to internet, the public endpoints are under

https://api.nuggad.net/ad_formats

There is a demo account you can use for authentication:

user: demo pass: demonugg

I had a problem in the live demo as well. Is there a case that the demo did not respond because I did not specify the header type in it? (it is application/json).

2011/12/22 Abdulrahman Alotaiba < reply@reply.github.com

I'm unable to access your resource URL to test and validate the issue. You could test your api on the live demo: http://alotaiba.github.com/FlyJSONP/#!/demo

If you're still unable to fetch the JSON response, then please let me know and put your resource live so I can debug and see what I can do.


Reply to this email directly or view it on GitHub: https://github.com/alotaiba/FlyJSONP/issues/1#issuecomment-3253454

alotaiba commented 12 years ago

Oh I see what's your problem there. The response is not a valid JSONP, it's a valid JSON though. FlyJSONP can only handle JSONP response.

I'm not sure if you can edit your Rails app to be able to produce JSONP responses. If you can, then make sure it can accept a GET parameter called callback, and to take that parameter's value to be the returned function callback name.

Here's an example: You current response is pure JSON, which looks something like this: {"Name": "Foo", "Id" : 1234, "Rank": 7}

You need to modify and wrap the response to look something like this: functionCall({"Name": "Foo", "Id" : 1234, "Rank": 7}); Where functionCall is the name of the GET parameter callback you're passing.

I hope that helps your issue, if not, then let me know.

alotaiba commented 12 years ago

Hi @akxs14, just wanted to make sure your issue is solved and whether to close the issue or not? If you have any further questions please feel free to add them.

akxs14 commented 12 years ago

Hi,

I was for vacation in an area without internet access and could not see my mails. I am back in office and going to test it tommorow and let you know.

Thank you for your immediate replies in which i was not so immediate.

Kind Regards

Angelos Kapsimanis

2012/1/2 Abdulrahman Alotaiba < reply@reply.github.com

Hi @akxs14, just wanted to make sure your issue is solved and whether to close the issue or not? If you have any further questions please feel free to add them.


Reply to this email directly or view it on GitHub: https://github.com/alotaiba/FlyJSONP/issues/1#issuecomment-3328952

akxs14 commented 12 years ago

It worked fine, you can consider it solved. Thank you for the great help!

2012/1/2 Angelos Kapsimanis angelos.kapsimanis@gmail.com

Hi,

I was for vacation in an area without internet access and could not see my mails. I am back in office and going to test it tommorow and let you know.

Thank you for your immediate replies in which i was not so immediate.

Kind Regards

Angelos Kapsimanis

2012/1/2 Abdulrahman Alotaiba < reply@reply.github.com

Hi @akxs14, just wanted to make sure your issue is solved and whether to close the issue or not? If you have any further questions please feel free to add them.


Reply to this email directly or view it on GitHub: https://github.com/alotaiba/FlyJSONP/issues/1#issuecomment-3328952