Welcome Guest, Not a member yet? Register   Sign In
using jquery ajax with codeigniter
#11

[eluser]benton.snyder[/eluser]
Code:
$.ajax({
  type: "POST",
  url: "http://127.0.0.1/index.php/ajax/username_taken",
  data: { username:username },
  success: function(msg) {
   $("#status").html(msg);
  }
});
#12

[eluser]johnpeace[/eluser]
[quote author="fatfishy" date="1352988813"]I guess you guys talked about this ?

http://i49.tinypic.com/14cxon4.jpg

then why am I getting 500 Internet Server error ?[/quote]

Because your CI code doesn't work for some reason...

I'm wondering why you're doing this:

Code:
$this -> db -> where('username = ' . "'" . $username . "'");

When you could just...

Code:
$this -> db -> where('username', $username);

If it were me, I'd try just hitting that controller method as a direct browser request and testing the results there. Turn on the profiler to display all of the queries being run and turn error reporting up.

In your controller...
Code:
$this->output->enable_profiler(TRUE);
#13

[eluser]fatfishy[/eluser]
I tried to post the full url, as you'r code does .. but I still get
-- Status Code:500 Internal Server Error --

but when I manually get into - http://127.0.0.1/index.php/ajax/username_taken
it works .. (gives an error, Message: Undefined index: username Filename: controllers/ajax.php which is ok ...) and printing "not exists" which is also ok,

what can cause the problem ? why the ajax cant rich the controller ?

thanks!
#14

[eluser]charly71[/eluser]
Try to use Input class library (http://ellislab.com/codeigniter/user-gui...input.html) and then get your username value directly in the model:

Code:
<?php
class Login extends CI_Model {


function login_check()
{
  $username = $this->input->post('username');
  $this -> db -> select('id, username');
  $this -> db -> from('users');
  $this -> db -> where('username = ' . "'" . $username . "'");
  $this -> db -> limit(1);

  $query = $this -> db -> get();

  if($query -> num_rows() >= 1)
  {
   return true;
  } else
   return false;
}
}

?>

Bye
#15

[eluser]fatfishy[/eluser]
[quote author="charly71" date="1352989812"]Try to use Input class library (http://ellislab.com/codeigniter/user-gui...input.html) and then get your username value directly in the model:

Code:
<?php
class Login extends CI_Model {


function login_check()
{
  .....
}

?>

Bye[/quote]

huh? what it has to do with the ajax-request problem ?
#16

[eluser]johnpeace[/eluser]
Quote:huh? what it has to do with the ajax-request problem ?

Nothing...but it's another example of your general lack of command of the CI framework. So you're being offered input that will help to expand your toolset.

Have you tried using the FULL url in the jQuery .post method?

Code:
url: http://127.0.0.1/index.php/ajax/username_taken
#17

[eluser]fatfishy[/eluser]
[quote author="johnpeace" date="1352990156"]
Quote:huh? what it has to do with the ajax-request problem ?

Nothing...but it's another example of your general lack of command of the CI framework. So you're being offered input that will help to expand your toolset.

Have you tried using the FULL url in the jQuery .post method?

Code:
url: http://127.0.0.1/index.php/ajax/username_taken
[/quote]

yes, same problem.
#18

[eluser]Mirge[/eluser]
Check your error log to see why it's throwing a 500 error.
#19

[eluser]benton.snyder[/eluser]
Did you change the $.ajax() data: variable too? Can you please screen capture the client post details so we can see what is being passed to the server? In these cases, 500 errors usually means you're passing incorrect or invalid data inside the request.
#20

[eluser]fatfishy[/eluser]
yes, ive changed the $.ajax() data: variable too!
Code:
$.ajax({
  type: "POST",
  url: "http://127.0.0.1/index.php/ajax/username_taken",
  data: { username:username },
  success: function(msg) {
  alert("asD");
   $("#status").html(msg);
  }
});

and here is the ss - http://s12.postimage.org/o3c5xnuj1/error.jpg

[quote author="Mirge" date="1352991465"]Check your error log to see why it's throwing a 500 error.[/quote]
I tried now to turn on the logs and see what is says but I don't see something about it,
Quote:DEBUG - 2012-11-15 16:48:38 --> Config Class Initialized
DEBUG - 2012-11-15 16:48:38 --> Hooks Class Initialized
DEBUG - 2012-11-15 16:48:38 --> Utf8 Class Initialized
DEBUG - 2012-11-15 16:48:38 --> UTF-8 Support Enabled
DEBUG - 2012-11-15 16:48:38 --> URI Class Initialized
DEBUG - 2012-11-15 16:48:38 --> Router Class Initialized
DEBUG - 2012-11-15 16:48:38 --> No URI present. Default controller set.
DEBUG - 2012-11-15 16:48:38 --> Output Class Initialized
DEBUG - 2012-11-15 16:48:38 --> Security Class Initialized
DEBUG - 2012-11-15 16:48:38 --> Input Class Initialized
DEBUG - 2012-11-15 16:48:38 --> XSS Filtering completed
DEBUG - 2012-11-15 16:48:38 --> XSS Filtering completed
DEBUG - 2012-11-15 16:48:38 --> XSS Filtering completed
DEBUG - 2012-11-15 16:48:38 --> CRSF cookie Set
DEBUG - 2012-11-15 16:48:38 --> Global POST and COOKIE data sanitized
DEBUG - 2012-11-15 16:48:38 --> Language Class Initialized
DEBUG - 2012-11-15 16:48:38 --> Loader Class Initialized
DEBUG - 2012-11-15 16:48:38 --> Database Driver Class Initialized
DEBUG - 2012-11-15 16:48:38 --> Controller Class Initialized
DEBUG - 2012-11-15 16:48:38 --> Helper loaded: form_helper
DEBUG - 2012-11-15 16:48:38 --> Form Validation Class Initialized
DEBUG - 2012-11-15 16:48:38 --> File loaded: application/views/test.php
DEBUG - 2012-11-15 16:48:38 --> Final output sent to browser
DEBUG - 2012-11-15 16:48:38 --> Total execution time: 0.1645
DEBUG - 2012-11-15 16:48:40 --> Config Class Initialized
DEBUG - 2012-11-15 16:48:40 --> Hooks Class Initialized
DEBUG - 2012-11-15 16:48:40 --> Utf8 Class Initialized
DEBUG - 2012-11-15 16:48:40 --> UTF-8 Support Enabled
DEBUG - 2012-11-15 16:48:40 --> URI Class Initialized
DEBUG - 2012-11-15 16:48:41 --> Router Class Initialized
DEBUG - 2012-11-15 16:48:41 --> Output Class Initialized
DEBUG - 2012-11-15 16:48:41 --> Security Class Initialized
DEBUG - 2012-11-15 16:48:41 --> Input Class Initialized
DEBUG - 2012-11-15 16:48:41 --> XSS Filtering completed
DEBUG - 2012-11-15 16:48:41 --> XSS Filtering completed
DEBUG - 2012-11-15 16:48:41 --> XSS Filtering completed
DEBUG - 2012-11-15 16:48:41 --> XSS Filtering completed

thanks!




Theme © iAndrew 2016 - Forum software by © MyBB