Jquery ajax success function returns null? |
[eluser]explorercode[/eluser]
@BrianJM I really appreciate your help. This thing is driving me crazy,.. I feel all the pieces and parts are in place, but I am still getting null. So, I am using the REST_Controller API posted by Philip Sturgeon in nettusplus - working-with-restful-services-in-codeigniter-2 article In this model when you include the /format/json at the end of the api url, it already encodes it with json_encode for you, so my controller doesn't have to do that. I wish I would post the API URL here so you see the results I get on the browser for the results... here it is -> my-domain-list.com / api / index.php/ whoisapi/ domain/ id/testingapi/format/json the whoisapi class has a method called domain_get() which translates into the domain method with a get type by the REST_Controller.
[eluser]explorercode[/eluser]
The whoisapi class looks like this now: Code: class Whoisapi extends REST_Controller Code: type: "GET",
[eluser]InsiteFX[/eluser]
Maybe you need this: Code: // Define Ajax Request - Place in application/config/constants.php InsiteFX
[eluser]BrianJM[/eluser]
InsiteFX, there's nothing wrong with the data output. The data is valid JSON and the response header is correct. [quote author="explorercode" date="1296115423"]@BrianJM I really appreciate your help. This thing is driving me crazy,.. I feel all the pieces and parts are in place, but I am still getting null. So, I am using the REST_Controller API posted by Philip Sturgeon in nettusplus - working-with-restful-services-in-codeigniter-2 article In this model when you include the /format/json at the end of the api url, it already encodes it with json_encode for you, so my controller doesn't have to do that. I wish I would post the API URL here so you see the results I get on the browser for the results... here it is -> my-domain-list.com / api / index.php/ whoisapi/ domain/ id/testingapi/format/json the whoisapi class has a method called domain_get() which translates into the domain method with a get type by the REST_Controller.[/quote] explorercode, no problem! I am able to make this work on my server using your json data. Take a look at the source code (I can't post the full source here because I'm new to the forums). On your server you should be able to use the same function, replacing "proxy.php" for the URL, and it should work. URL: (remove underscores) brianjm_._com/explorercode/
[eluser]explorercode[/eluser]
Thank you so much... I see the site working on your server... very nice.. now... what is the code on brianjm_._com/explorercode/proxy.php how did you create the proxy.php? can you send me the code for it? sorry, I am new to codeignter if the proxy is common knowledge.. thx
[eluser]BrianJM[/eluser]
[quote author="explorercode" date="1296120240"]Thank you so much... I see the site working on your server... very nice.. now... what is the code on brianjm_._com/explorercode/proxy.php how did you create the proxy.php? can you send me the code for it? sorry, I am new to codeignter if the proxy is common knowledge.. thx[/quote] Attempting to retrieve the output of a page on your domain, from my domain, is cross site scripting (it would fail for this reason alone). To provide a working example I created proxy.php which retrieves the response from the URL you provided me. You should not have to use this, it does not come with CI, and I don't recommend using it; again, I only used proxy.php to be able to use your live data in my working example. You should be able to use the JavaScript in the source I provided, on your domain, replacing 'proxy.php' with your URL, and it should work. If it does not then there is something else wrong here. Are you violating the Same Origin Policy? Data cannot come from another server, another port, or another protocol ("http:" vs "https:" vs "file:") than the current page. Give the code a try to let us know what the result is. Here is proxy.php (because you asked): Code: <?php
[eluser]explorercode[/eluser]
Thanks. I'll try to implement that code, but what puzzles me is that the url is a RESTFul API. It should work from any domain. Is it a specific PHP restriction with Ajax. I am not sure what platform Twitter created their APIs, but if I switch to a Twitter URL(http_:_//_twitter.com/users/show/{username}.json) in the ajax code above, I get the actual data. I may have to write my RESTful service in another platform.
[eluser]BrianJM[/eluser]
[quote author="explorercode" date="1296180484"]Thanks. I'll try to implement that code, but what puzzles me is that the url is a RESTFul API. It should work from any domain. Is it a specific PHP restriction with Ajax. I am not sure what platform Twitter created their APIs, but if I switch to a Twitter URL(http://twitter.com/users/show/{username}.json) in the ajax code above, I get the actual data. I may have to write my RESTful service in another platform.[/quote] XMLHttpRequest (AJAX) is subject to the Same Origin Policy. Simply replacing the URL with the one you provided still does not work, for the same reason. You have to use JSONP in order to bypass the SOP restriction (http://twitter.com/users/show/{username}...ckFunction). Again, here is an example of what does NOT work: http://brianjm.com/explorercode/twitter.html. REST is an architecture style. You are, at the core, using Asynchronous JavaScript and PHP. The Same Origin Policy applies.
[eluser]explorercode[/eluser]
I tried using jsonp as well.. including a callback method....to the URL, but that is still returning null. Do you have advise on using jsonp with the following URL? http:_//_my-domain-list.com/api/index.php/whoisapi/domain/id/progressive.com/format/jsonp/callback/testing thanks
[eluser]BrianJM[/eluser]
I don't think you have clarified if you are violating the Same Origin Policy or not. What is the URL (or at least the domain) you are using that is attempting the AJAX call? |
Welcome Guest, Not a member yet? Register Sign In |