views:

696

answers:

3

I'm trying to load or better reload a DIV with content from an included php file. so the file is included in the webadmin.php from the location webadmin/pages.php. Then i alter some data in the DB through serializing.

Now I would like to reload the pages.php from the callback of the serialize POST with load();. This all works fine up until the moment the data is supposed to be displayed in the div - i believe its because the php file is loaded from a different location, so the include paths for the DB Connection etc are probably wrong...

Should I really write an extra PHP File for jquery or is there a way to tell jquery where to load it from?

Its the first time I'm doing this - so bear with me for a moment on this one... Thanks!

I guess it wont be much use, but heres the load code:

$("#right").load("webadmin/pages.php");
A: 

Is the load() function returning anything?

The script is not location dependent in terms of the DB includes, etc. Those includes are only relative to the PHP script itself. The ajax function is running client side, so imagine that it's calling the URL relative to the same place as the original page. So if your page is:

 http://example.com/stuff/page.php

and you are calling the script at:

 webadmin/pages.php

Then the URL the ajax load method is using is:

http://example.com/stuff/webadmin/pages.php

This is the exact same as if you are putting in an href for a link or a src for an image. If the script actually is at:

http://example.com/webadmin/pages.php

Then you need to change the load URL accordingly (same as if an image were in a lower directory) like so:

 $("#right").load("../webadmin/pages.php");
Anthony
It's worth noting that if webadmin is always at the root, you can just use a slash before it without any .. junk. Example: `/webadmin/pages.php` will always go to http://www.example.com/webadmin/pages.php even if the page is at http://www.example.com/a/b/c/d/e/something.php
icktoofay
yeah, full path will work too. Just didn't want to do my usual overkill.
Anthony
Thanks for the answer. Yes the load() is returning the first part of the php file - i created a special pages.ajax.php file with correct paths - still the same issues only a part gets loaded and also this is in UTF8 - I'm using iso-8859-1 - so there is another big hickup there...
Mark Nolan
Is the PHP returning the unloaded portion or is it being dropped by the ajax? Have the ajax load the response into a textarea or have the php escape the code first, to be sure that something in the response itself isn't getting mangled by the browser.
Anthony
A: 

You can use Firebug, then open Net tab to see if there are response from the AJAX call.

I never use $.load(), instead I use $.get or $.post:

$.get("webadmin/pages.php",
      { nbRandom: Math.random() },
      function(data){
        $("#right").html(data);
      });

nbRandom is just to prevent caching in IE. Choose a name that not used in the pages.php

Make sure no error in Firebug, and the page structure is a valid HTML/XHTML. Some bug is occurred because imbalanced tags in page.

Donny Kurnia
Thanks - now it works. Don't know why exactly - even the load works now!? but still the UTF8 Problem remains... so all my äöü and such are out. And to add onto that, the list I'm loading has jQuery UI buttons attached for each line - these don't work either. Seems like JS can't handle the buttons beeing reloaded. Any ideas here?
Mark Nolan
I converted my site to UTF8 - those problems were a timebomb anyway...its still not loading properly, i guess i just have to fiddle around some more :-)
Mark Nolan
A: 

$.get("webadmin/pages.php", { nbRandom: Math.random() }, function(data){ $("#right").html(data); }); this code is including php file wiht using jquery thanks

Skywolfyx1