• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
One of my controllers refuses to load any views!

Will post the missing pieces ASAP, but in the mean time, would AJAX be a factor in CodeIgniter deciding when to load a view and when to redirect??

You could be outputting 1 from ajax after receiving the result instead of showing the result. Just trying to be thorough and can't really know without all relevant pieces of code.

Hmm....yeah, I think that AJAX thing is a problem....I think I'm doing too much from a single AJAX call. I think what I'll do is toy with having do_search() return the array to Javascript and work from there...

[eluser]Tim Brownlaw[/eluser]
While you are gathering your code to post in here so we can see what is actually happening, just a thought!!!
Which is probably totally useless as it sounds like there is an AJAX call happening in between...
[quote author="dauber" date="1407522044"]
- Replaced that line in do_search() with this:

and added this function to the controller:

function display_results() {
        error_log("display results");

Result: same thing: blank page, with "1" in the source code and nothing else.

And the error log didn't have "display results" in it, so that redirect wasn't even firing.
Have you loaded the url helper either in your autoload.php or in your controller as

The redirect() function needs the url helper to make it work... It sounds like it isn't being loaded which would be due to the fact you wouldn't be using internal redirects when making AJAX calls!

Another thought! Can you call your do_search method directly via the url?
ie sitename.com/scrchgames_ctrl/do_search
What does that do?

What does that do? It makes a hot mess -- I need to pass some parameters for the SQL to work. Smile

Weird thing now....the callback function in the AJAX call doesn't fire. Ahhh, here comes more fun.

[eluser]Tim Brownlaw[/eluser]
Well get your code posted on here!

It only allows so many characters! But here's the controller as it exists now -- I want it to return the array to the AJAX call (URL helper is in autoload, btw):


class Srchgames_ctrl extends CI_Controller {
    function __construct() {
    function do_search() {
        if ($_POST['a2600'] === 'true') {
            $search_games['console'][] = '2';
        if ($_POST['a5200'] === 'true') {
            $search_games['console'][] = '5';
        if ($_POST['a7800'] === 'true') {
            $search_games['console'][] = '7';
        $search_games['manual'] = $_POST['manual'];
        $search_games['box'] = $_POST['box'];
        $search_games['notes'] = $_POST['notes'];
        $search_games['emanual'] = $_POST['manual'];
        $search_games['ebox'] = $_POST['box'];
        $search_games['enotes'] = $_POST['notes'];
        $search_games['include']['smanual'] = $_POST['manual'];
        $search_games['include']['sbox'] = $_POST['box'];
        $search_games['include']['snotes'] = $_POST['notes'];
        $search_games['search_terms'] = $_POST['search_terms'];
        $search_games['search_key'] = $_POST['search_key'];
        $search_games['rarity_fuzz_drop'] = $_POST['rarity_fuzz_drop'];
        $search_games['rarity_options'] = $_POST['rarity_options'];
        $search_games['aah'] = $_POST['aah'];
        $search_games['aar'] = $_POST['aar'];
        $search_games['aap'] = $_POST['aap'];
        $search_games['aau'] = $_POST['aau'];
        $search_games['include']['gamePlatform'] = $_POST['splatform'];
        $search_games['include']['atariagecom_rarity'] = $_POST['rarity'];
        $search_games['include']['cartColor'] = $_POST['cart_color'];
        $search_games['include']['labelCase'] = $_POST['label_case'];
        $search_games['include']['labelStyle'] = $_POST['label_style'];
        $search_games['include']['overlay'] = $_POST['overlay'];
        $search_result = $this->srchgames_model->search_games($search_games);
        return $search_result;
        error_log("If you can read this, it didn't return.");

Here's the AJAX call:

function validate_list_form() {
    var errors = new Array();
    var form_data = new Array();
    if (($('#a2600').prop('checked') !== true) && ($('#a5200').prop('checked') !== true) && ($('#a7800').prop('checked') !== true)) {
        alert("You need to choose at least one console.");
        return false;
    } else {
        $.post('/index.php/srchgames_ctrl/do_search', {
            'a2600': $('#a2600').prop('checked'),
            'a5200': $('#a5200').prop('checked'),
            'a7800': $('#a7800').prop('checked'),
            'manual': $('#manual').prop('checked'),
            'box': $('#box').prop('checked'),
            'notes': $('#notes').prop('checked'),
            'emanual': $('#emanual').prop('checked'),
            'ebox': $('#ebox').prop('checked'),
            'enotes': $('#enotes').prop('checked'),
            'search_terms': $('#search_terms').val(),
            'search_key' : $('#search_key').val(),
            'rarity_fuzz_drop' : $('#rarity_fuzz_drop').val(),
            'rarity_options' : $('#rarity_options').val(),
            'aah': $('#aah').prop('checked'),
            'aar': $('#aar').prop('checked'),
            'aap': $('#aap').prop('checked'),
            'aau': $('#aau').prop('checked'),
            'splatform': $('#splatform').prop('checked'),
            'smanual': $('#smanual').prop('checked'),
            'sbox': $('#sbox').prop('checked'),
            'snotes': $('#snotes').prop('checked'),
            'rarity': $('#rarity').prop('checked'),
            'cart_color': $('#cart_color').prop('checked'),
            'label_style': $('#label_style').prop('checked'),
            'label_case': $('#label_case').prop('checked'),
            'overlay': $('#overlay').prop('checked')
        }, function(result) {
            console.log("Here's the result");
        }).done(function() {

[eluser]Tim Brownlaw[/eluser]
Ok that's not overly convoluted... Smile

So what do you get in console message.

I'm guessing if you use Firefox you'd have firebug to see what's coming and going ( using the console ) and Chrome also has the same kind of feature for debugging javascript/ AJAX calls etc...

You should be able to see what is being sent to confirm it's correct and see the response and your console messages.

But I'd be taking it back a few steps to narrow down where the actual issue lays because there's a ton of reasons that could cause the world to go upside down.

ie if you do feed known good SQL parameters to your do_search() ( taking the whole AJAX thing out of the picture ) does that work! And never forgetting - Bad ones as well... And work your way back from there.

You want overly convoluted? Well, the model generates SQL on the fly based on what's submitted via AJAX. Smile (And I can confirm from the PHP error log that it does generate valid SQL statements that actually get the MySQL results that I want!)

Firebug is completely blank except the indication that do_search() has fired. It shows the stuff that posted, but no response. Nothing.


BTW, I've since added .fail() and .always() AJAX callbacks. The .always() one does indeed fire but with empty results. Nothing else fires, though.

Oh, great....and now my error log no longer writes. Sad


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.