[英]Can't send content-type: text/xml header from PHP at the same time getting the data from MYSQL
我希望你能对我的问题有所帮助。 我需要做一个AJAX / PHP / MYSQL应用程序才能在我正在写的页面上显示帖子和内容。
我只是在吃了一些蘑菇之后才发现如何在PHP中做一些简单的事情,但是那是几年前的事,现在我没有蘑菇了,我只是被卡住了!
所以这是问题所在:
我认为我需要通过php发送适当的“ xml”文件,以便ajax部分可以接受它,但是:当我尝试将标头放在php顶部时,它将显示此错误:
“文档末尾的其他内容”
当我看一些教程时,人们正在恐惧地使用“标题”来做我想做的事情,没有评论表明它不起作用。 那为什么它在我的本地服务器上不起作用?
我在跑:
WAMP Apache 2.2.11 PHP 5.3.0
它也不能在远程服务器(PHP 5.3.0)上运行:/
我读到了凌晨5点为止我能找到的所有东西,并决定第一次向您寻求帮助:)
谢谢!
header('content-type: application/xhtml+xml; charset=utf-8');
require_once("allyouneed.php");
require_once("bazingablob.php");
$category=$_GET["category"];
$post_tags=$_GET["post_tags"];
$language=$_GET["language"];
$author=$_GET["author"];
$posts_per_page=$_GET["posts_per_page"];
$current_page=$_GET["current_page"];
$order=$_GET["order"];
$hard_limit=$_GET["hard_limit"];
$show_hidden=$_GET["show_hidden"];*/
$wypluj="";
$wypluj="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
$bazinga_blob = new bazingablob;
if (!$bazinga_blob->connect_to_database())
{
$wypluj.="<IsOK>0</IsOK>";
echo $wypluj;
exit;
}
else
{
$wypluj.="<IsOK>jedziem</IsOK>";
}
$bb_result=$bazinga_blob->get_all_posts($category,$post_tags,$language,$author,$posts_per_page,$current_page,$order,$hard_limit,$show_hidden);
if ($bb_result) //udalo sie cos znalezc w bazie wedlug kryteriow
{
$wypluj.="<Pagination>";
$wypluj.="<CurrentPage>";
$wypluj.=$bazinga_blob->posts_pagination["current_page"];
$wypluj.="</CurrentPage>";
$wypluj.="<LastPage>";
$wypluj.=$bazinga_blob->posts_pagination["last_page"];
$wypluj.="</LastPage>";
$wypluj.="<PostsCount>";
$wypluj.=$bazinga_blob->posts_pagination["posts_count"];
$wypluj.="</PostsCount>";
$wypluj.="</Pagination>";
$wypluj.="<Posts>";
foreach ($bb_result as $item)
{
$wypluj.="<Post>";
$wypluj.="<PostId>".$item->post_id."</PostId>";
$wypluj.="<PostAuthor>".$item->post_author."</PostAuthor>";
$wypluj.="<PostLangId>".$item->post_langid."</PostLangId>";
$wypluj.="<PostSlug>".$item->post_slug."</PostSlug>";
$wypluj.="<PostTitle>".$item->post_title."</PostTitle>";
$wypluj.="<PostGreetingPicture>".$item->post_greeting_picture."</PostGreetingPicture>";
$wypluj.="<PostGreetingVideo>".$item->post_greeting_video."</PostGreetingVideo>";
$wypluj.="<PostGreetingSound>".$item->post_greeting_sound."</PostGreetingSound>";
$wypluj.="<PostShort>".$item->post_short."</PostShort>";
$wypluj.="<PostBody>".$item->post_body."</PostBody>";
$wypluj.="<PostDate>".$item->post_date."</PostDate>";
$wypluj.="<PostPublished>".$item->post_published."</PostPublished>";
$wypluj.="<PostSticky>".$item->post_sticky."</PostSticky>";
$wypluj.="<PostComments>".$item->post_comments."</PostComments>";
$wypluj.="<PostProtected>".$item->post_protected."</PostProtected>";
$wypluj.="</Post>";
}
$wypluj.="</Posts>";
}
echo $wypluj;
老实说,我不确定您要使用标头做什么,这不是我曾经教过的任何Ajax方法。 您正在执行的header方法看起来仅比将XML输出到下载提示少了几行。
这是我最喜欢的AJAX方式。 简单,易懂且快速。
这是一个很棒的教程 。 专注于“ Hello Ajax,Meet Jquery”下的代码
如果您能从中获得更多收益,那么XAJAX是PHP熟悉的AJAX制作方法。 它允许您对PHP函数进行异步调用。 但是请注意,论坛不是最英语友好的,并且文档有点含糊。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.