Ajax Framework (CJAX) for Codeigniter 2.x+ |
[eluser]gwatt[/eluser]
Hi Cj, About the relative URL thing. Using base_url DOESN'T work and was generating the same crossdomain request. That is what I was using originally but I just put in the whole URL in my post to be clear. Because it's part of Code Igniter I really was expecting this to work. I didn't see anything in the online documentation about having to use relative URLs and in the examples that come with CJAX for CI there is no Code Igniter controller file that shows how to link to an AJAX request. Maybe this is obvious for AJAX developers but I spent a week pulling my hair out. One included file like below would have made things very clear: ------------ <?php class Cjaxtest extends CI_Controller { public function test() { require_once(FCPATH.'ajaxfw.php'); $this->load->view('cjaxtest'); $ajax = ajax(); $ajax->click('#click_div',$ajax->call('../../ajax.php?click/update/')); } } --------------- Anyway I appreciate the work the AJAX library must have taken and thank you for releasing it. Now I can start actually using it! G
[eluser]Ajaxboy[/eluser]
I think I miss quoted instead of base_url(), I meant site_url(). Eg: $ajax->call(site_url(’ajax.php?click/update/’)); This is what I meant from the beginning. As I mentioned before, it is better practice to let CI generate the url for you, instead of hard coding it, specially Hardcoding full path urls. Yes, Cjax is an ongoing project and has taken many years to develop into the framework that is today, started since 2006, and have evolved over time, re-rewritten to meet the newest technology and continue to be maintained. I can gladly say it is bug free, in the past year no bugs have been found, other than people having requirement/settings issues. It would be nice if you could leave a review here: I will very much appreciate, and thank you. http://sourceforge.net/projects/cjax/reviews/ (click where it says "Write Review")
[eluser]gwatt[/eluser]
Hi CJ, Using the site_url() function from the URL Helper doesn't make any sense. ----According to the Code Igniter manual --- site_url() Returns your site URL, as specified in your config file. The index.php file (or whatever you have set as your site index_page in your config file) will be added to the URL, as will any URI segments you pass to the function, and the url_suffix as set in your config file. ------ The site index page should be the Code Igniter "index.php" page and NOT the ajax.php page. base_url() is basically the same but without the final page. ----Again from the Code Igniter Manual ------- base_url() This function returns the same thing as site_url, without the index_page or url_suffix being appended. -------------- However here is the problem as soon as I change this $ajaxlink = "../../ajax.php?ajax_vocab/answer_question/" . $value['word_id'] . "/" . $currentWordArray['word_id'] . "/" . $answerCount; to this $ajaxlink = base_url() . "ajax.php?controller=ajax_vocab&function=answer_question&a={$value['word_id']}&b={$currentWordArray['word_id']}&c=$answerCount"; CJAX returns the crossdomain link and it doesn't work. Even though they end up pointing to exactly the SAME place which is http://uebusaito.com/engproj/ajax.php?aj...n/42/204/0 Shouldn't this work? As you said it is best practice to NOT hard code URLS...
[eluser]Ajaxboy[/eluser]
Can you also give an example how you used site_url()? Before we get too complicate, please notice I said this: Quote:you can always use built in function base_url() or create a similar functions, or a constant that can hold the relative path to a url so it’s easier to place around. If any of these functions don't work for you, just create your own, is pretty much what I said. eg: function my_url($url) { return "../.../", $url; } $ajax->click(’#click_div’,$ajax->call(my_url(’ajax.php?click/update/’))); Should make this so much easier for you. I am unable to test any code at this moment since my computer environment crashed and I am on a temporary computer for the time being. But basically I am suggesting don't get too complicate just make a function , at least for now until you figure something out.
[eluser]gwatt[/eluser]
Hi CJ, I will do that in the mean time. The only complication is that there could be an unknown amount of variables after the controller and function For example site.com/index.php/controller/function/1/1/2/4/3/3 So I guess I have to build a function to count how many variables there are in the site url and add extra "../" based on this. Although I really feel to integrate properly with Code Igniter site_url() and base_url() should work because it's not changing the domain. My code is very simple but I even setup a clean test of Code Igniter and CJAX and the same thing happens. So I find it strange I'm the only one who has encountered this. It seems very simple but I can't see any other posts about this. Very strange. I will email you the clean test version I setup that has this problem this week. Thanks for your help. G
[eluser]Ajaxboy[/eluser]
Your issue really has nothing to do with Cjax, and more with basic url handling of the URL helper. What I said above was from the top of my mind, but I can't really confirm the functions above since I am unable to test at this moment and is outside of the scope of Cjax. So I'd take it you need to look more into how CI handles the URL.
[eluser]gwatt[/eluser]
Hi, It just returns a string based on site settings. I'm not saying there is an CJAX bug but my question is this... Why does calling this CJAX link uebusaito.com/engproj/ajax.php?controller/function/ from this URL uebusaito.com/engproj/index.php/controller/function/ result in a crossdomain request that doesn't work? Surely CJAX should recognise that it's the same domain: uebusaito.com This has nothing to do with the Code Igniter functions because they return the same thing. I'm not sure if this only doesn't work for Code Igniter URLs but my point is for "CJAX for Code Igniter" to be fully compatible with Code Igniter it should work with Code Igniter URLS without having to write special functions to encode the URLs relatively. Otherwise there should be something in the documentation that warns people that it is not fully compatible with Code Igniter URLs. I'm only saying this because it is called "CJAX for Code Igniter" and so I assumed that this would work. I know you are doing this for free and I saw somewhere that you wanted people to help with documentation. I would be willing to help with this if I knew more about what was going on. It's maybe not a bug but for Code Igniter I feel like this is a really basic thing that should work "out of the box"... G
[eluser]Ajaxboy[/eluser]
I think it has to do with the server response?. Some servers monitor how a request is made and limit "none" regular browser requests. Ajax is meant to be used locally/relative not across domains. The fact that cjax allows to retrieve data from across domains, is a unique feature that no other Ajax application allows. However you should try to use a relative url when using ajax, it is just common practice, some times there are issues when using the full url in ajax. I assume, you are using source forge as host? since that is what was displayed on the request earlier. They do have that limitation and not allow remote requests. But I do see how someone's intention to want to enter an absolute url for a local ajax request, the problem with this is that is not consistent and some browsers/servers have limitations with this action and that is why is treaty as an entire "foreign" url, however I see how someone would want to do that if they chooses to and their host allows it, in a future version I will introduce a setting where you can allow local request with full url for anyone who wants to do that. Though, it was avoided for a reason.
[eluser]gwatt[/eluser]
OK, I see. My site is hosted on shared virtual setup with Globat.com. It has been good and completely like a dedicated server so far nothing strange. I have a local "instance" of the server and php settings that I can change if there is something I can do there. I have no idea where the sourceforge stuff is coming from. I have nothing on my server and nothing in my code relating to sourceforge. I thought that CJAX was creating that from somewhere. If I call http://uebusaito.com/engproj/ajax.php?co...r/function Then open the created crossdomain link it shows a page that looks like sourceforge (but the URL is the crossdomain link) I can't imagine why it would do this.. the crossdomain link is being created by CJAX... G
[eluser]Ajaxboy[/eluser]
If I could test I would look a way around for you but like I mentioned I don't have a development environment at my disposal right now - so any changes I make outside my development environment would not be available to anyone in a future release. Besides this I do have a server online but I will only do extra work for you if you commit to leave a review, as requested in one of the posts above. |
Welcome Guest, Not a member yet? Register Sign In |