• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JQuery and Ajax Issue

#31
[eluser]alboyd[/eluser]
nvm - it checks if it's there and adds if not...

#32
[eluser]alboyd[/eluser]
mate.. I've replicated your code on my machine and I had major problems with your declaration of the array variable in javascript. But works when you do it like this:
Code:
var series = new Array();

And I get Hello returned to content just fine.

Can't see how there would be a problem if i loaded it onto my web host.

How on earth did your var series{}; work in any location is beyond me..

#33
[eluser]Bendude[/eluser]
I was using var series = {};

Thought that was short hand for initialising an array.

I have changed it like you said and now I receive a 404 on this function with the base url

Code:
<?php $base = base_url(); ?>
     var str = "";
     var url = "<?php echo $base . 'home/viewAll';?>";
     $('#houses').load( url, series, function(str){} );

And your version of the function does not trigger a Http request

Code:
function viewAll()
            {

                $("a#view_all").click(function()
                {
                    var base_url = "<?php echo base_url(); ?>";
                    var series = new Array();
                    var url = base_url + "home/viewAll";    
                    $("#houses").load( url, series, function(){} );

                    return false;
                });
            }

#34
[eluser]alboyd[/eluser]
No... that's not what my version looks like... it's not a javascript function...

Inside your script should have something like this:
Code:
var base_url = "<?php echo $base_url; ?>";

$(document).ready(function() {

    $("a#view_all").click(function() {
        
        var series = new Array();
        series['id'] = 1;
        var url = base_url + "controller/controller_function";    
        $("#content").load( url, series, function(){} );

        return false;
    });

    
});

#35
[eluser]Bendude[/eluser]
Ok I just used your method exactly as shown and it works locally even though it seems rather slow, but still I get no response or error on the server. It is like JQuery is not attaching the event handler to the link as it still adds the hash to the URL?

#36
[eluser]alboyd[/eluser]
You link should not be doing any on_click things right?

Should just be the link like i put in my prev example.

If it's not binding then is the link appearing through ajax as well? If so you will need to use it live.
Code:
$("a#view_all").live("click", function() {
// do your stuff here
});

#37
[eluser]Bendude[/eluser]
well think im about back where i started, works fine locally with your code but on the server i just keep getting 404 not found. Thats for both relative and absolute urls. Do you think it could be my .htaccess messing it up?

#38
[eluser]alboyd[/eluser]
Could be mate.. Try this one:

Don't forget to change the
Code:
<IfModule mod_rewrite.c>
    #http://codeigniter.com/wiki/mod_rewrite/
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>


You need to change RewriteBase to your base url. EG:
Locally my base is http://localhost/sitename so rewritebase is "/site/"

On my web host it's just "/"

#39
[eluser]Bendude[/eluser]
Nope same difference, I wonder what else could be wrong, I can not see the results of the controller method if i try to access the URL manually either. I still get the 404

Yet locally it works fine, and obviously I know it exists

#40
[eluser]alboyd[/eluser]
Your server probably doesn't like you using htaccess - you will need to turn it on somehow... google it... prove this by putting in index.php/controller/function


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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