CodeIgniter Forums
Database LiveSearch - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Database LiveSearch (/showthread.php?tid=52125)

Pages: 1 2 3 4


Database LiveSearch - El Forum - 05-30-2012

[eluser]sanir[/eluser]
ok, now check through search area.


Database LiveSearch - El Forum - 05-30-2012

[eluser]boltsabre[/eluser]
Quote:Message: Undefined index: partialSearch
You're not getting your post array index "partialSearch"

Code:
function getSearchResults(value) {
   alert(value)
   $.post("getSearchResults.php",{partialSearch:value}, function(data){
    $("#search_results".html(data));
   });
and alert/check if value actually contains something. If it doesn't $_POST['partialSearch'] will be empty, thus false, thus undefined (I think).


Database LiveSearch - El Forum - 05-30-2012

[eluser]joe.afusco[/eluser]
Alert is working fine.


Database LiveSearch - El Forum - 05-30-2012

[eluser]boltsabre[/eluser]
Okay, so your alert is alerting your value, so we know that that is working
Code:
public function getSearchResults()
{
// $this->load->database();  
  $partialSearch = $_POST['partialSearch'];
  var_dump($partialSearch);
and comment out the rest of the code, what kind of variable is $partialSearch?

And are there any error in Firebug console?


Database LiveSearch - El Forum - 05-30-2012

[eluser]joe.afusco[/eluser]
$partialSearch is a string. It will be used to reference phone numbers. since it is currently checking users email address', I keep searching for the first few characters of my email that is on the user table.

firebug console shows:

POST http://localhost/crm/index.php/search/getSearchResults 500 Internal Server Error


Database LiveSearch - El Forum - 05-30-2012

[eluser]boltsabre[/eluser]
Are you sure CSRF is not set to true in your config file?



Database LiveSearch - El Forum - 05-30-2012

[eluser]joe.afusco[/eluser]
Hmm. It was set to true. Sorry, when you asked if it was autoloaded earlier, I didn't set it to autoload. Didn't know it was in the config file. Sorry about that.

It is all working properly now. Thank you all for all the help.


Database LiveSearch - El Forum - 05-30-2012

[eluser]boltsabre[/eluser]
lol... yeah, okay, just so you know what was happening:
CSRF was set to true (to prevent against cross site hacking). Because you were submitting $_POST values but without the CSRF code/hash it was failing and returning the internal 500 error - which is a good thing!

Basically you want to keep it enabled/set to true, so your work is not quiet over yet. Just do a google on "codeigniter submit form via ajax with CSRF enabled" to figure it out, there are a couple of options (I'm at work, cannot remember the syntax off the top of my head).

Glad we got there in the end!