jquery load php file - result is not complete
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开发者_StackOverflow中文版 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");
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.
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");
$.get("webadmin/pages.php",
{ nbRandom: Math.random() },
function(data) { $("#right").html(data); }
);
this code is including php file with using jquery
精彩评论