Welcome Guest, Not a member yet? Register   Sign In
How to make Remote Function work in codeigniter framework?
#11

[eluser]n0xie[/eluser]
Code:
<th>Requested URL</th><td>http://localhost:80/accounts/check_user_availability?username=rrrfdgdf</td></tr>
Do you have query string enabled? CI disables $_GET array by default.
If you put go to the URL directly, what does CI return?
#12

[eluser]jiahui[/eluser]
I didn't use any $_GET array in my controller site

Code:
function check_user_availability()
        {
            $request = trim(strtolower($_REQUEST['username']));
            //sleep(2);
            usleep(150000);
            $users = array('asdf', 'Peter', 'Peter2', 'George');
            $valid = 'true';
            foreach($users as $user) {
                if( strtolower($user) == $request )
                    $valid = 'false';
            }
            echo $valid;
                    }

but I am using direct URL. There has nothing response from CI return.
Could you help? Appreciate if you can help me solve it.
#13

[eluser]Ben Edmunds[/eluser]
You can see in the url it generates

Code:
http://localhost:80/accounts/check_user_availability?username=rrrfdgdf

That username is being passed as a query string in the url.


Try turning on query strings in you config file.
#14

[eluser]jiahui[/eluser]
I'd been set it as
Code:
$config['enable_query_strings'] = True;
but it still work nothing.

I think mostly is URL cannot callback problem..... Any good solution about this? Please help... Thank you.

Code:
function check_user_availability()
        {
            $request = $this->input->post('username');
            
        /* Cannot response anything out by $this->input->post('username') */
            
                        $users = array('asdf', 'Peter', 'Peter2', 'George');
            $valid = 'true';
            foreach($users as $user) {
                if( strtolower($user) == $request )
                    $valid = 'false';
            }
            echo $valid;
                    }
#15

[eluser]jiahui[/eluser]
Nobody can help??
#16

[eluser]n0xie[/eluser]
Quote:but I am using direct URL. There has nothing response from CI return.
Could you help? Appreciate if you can help me solve it.
You are not really helping yourself or us. What happens when you go to the url directly?

Does it return a 404? Does it return an error? Do you get a blank page? Does your computer suddenly turn into a transformer and eat your lunch?

Your ajax requests gets a 404 which means it can't find the controller/method you are trying to access. It would be common sense to first make sure that your request gets handled properly...

So again, go to :
Code:
http://localhost:80/accounts/check_user_availability?username=rrrfdgdf

and try to figure out what's wrong before even starting to debug your javascript. It could be as simple as a misconfigured httpd.ini (would have been handy to mention you were using IIS). It could be as simple as adding index.php to the url. But since my crystal ball is broken I can't really say for certain.
#17

[eluser]jiahui[/eluser]
I am sorry. Honestly, I am very new in codeigniter. Perhaps I not very understand what you want me to do at first. Again, I am really frustrate on myself for doing research for this around 1 month ago. Till now I still cannot get the solution.

Code:
http://localhost/hoorfatt/index.php/accounts/check_user_availability?username=peter

I used above direct url to see what happen on that page. "The result is 404 page not found". What I not understand is I did enclose the function check_user_availability function in controller but why it still cannot work.....

Look forward your reply. Thanks in advance.
#18

[eluser]n0xie[/eluser]
Ok can you access another function inside controller accounts? Or just add this to your accounts controller and see if you can access it.

Code:
function testme()
{
  echo 'hello';
}
#19

[eluser]jiahui[/eluser]
if I use this direct url to access
Code:
http://localhost/hoorfatt/index.php/accounts/testme
I can see it.
#20

[eluser]garymardell[/eluser]
Turn the ajax request into a POST request rather than a GET one.

And then use $this->input->post('username'); to get the value.

I think your current problem is that you don't have query strings enabled and you haven't set the right URI_PROTOCOL in your config file. Some of them don't work on certain servers, if you go through them all and refresh the page (directly accessing the url) then you should find one that works. However it is probably easier to change it to a post request and the value will be escaped for you as well.




Theme © iAndrew 2016 - Forum software by © MyBB