2017-01-20 31 views
0

我完全失去了,我從我的其他apache服務器複製這個工程很好(我得到響應作爲json等......),現在我在其他apache服務器上嘗試了這一點,並且這不起作用(帖子進入服務器,但不作爲json)。如果我有'json'我沒有得到迴應(因爲我在php中有jsonencode,但是如果我只是迴應結果,它會回來,但是這個JavaScript永遠不會去函數(r),所以它甚至不會alert('test')jquery發表作品,但沒有與json

當我刪除'json'時,它工作得很好,但是我不能有正確的響應,因爲php處理它並將其返回到jsonencoded數組中。並表明我的結果...

沒有JavaScript錯誤或PHP錯誤。我甚至不知道從哪裏開始調試......

我也試過$阿賈克斯({equilevant這兩種方法和相同的結果。

$.post('request.php', { getcontent: 'modal' }, function(r) { 
    title.html(r.title); 
    content.html(r.content); 
    footer.html(r.btns); 
    $('#modal').modal('show'); 
    tinymce.remove(); 
    tinymce.init({ selector: 'textarea', plugins: 'link anchor code image fullscreen textcolor colorpicker' }); 
},'json'); 

回答

0

一些指點一下:

最後一個參數是響應的預期的數據類型,而不是發送的對象。也許php沒有正確接收這個帖子。

你可能想要在php中設置一個標題爲: header('Content-type: application/json'); 確保你的響應是在json中。

您的帖子的網址(request.php)可能無法訪問

+0

謝謝,本指南指向正確的路徑。問題是在文件編碼,它是ISO 8859-1,而不是utf8,所以任何文件必須在utf8或編碼結果像'exit( json_encode( array( 'title'=> utf8_encode($ title), '內容」 =>函數utf8_encode($ HTML), 'HTML編輯'=>函數utf8_encode($ S [ '內容']), 'btns'=>函數utf8_encode($ btns) ) ) );' 是誠實,這不是第一次,不幸的是上次編碼導致我頭痛。當然,在將它們移動到新的Apache服務器後,我沒有檢查文件編碼... – Diamonte

+0

很高興爲您提供幫助! 要一次對整個數組進行編碼: 'array_walk_recursive($ array,function(&$ item,$ key){if(!mb_detect_encoding($ item,'utf-8',true)){item = utf8_encode ($ item); } });' –

相關問題