[英]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.