問題は単純だと思いますが、私は無知で理解できません。
私のウェブサイトにはプロファイル フィードがあり、ユーザーは jquery の ajax 関数を使用して即座に表示されるステータスを投稿できます。
jqueryがエラーを言っているhtmlを投稿しようとすると、新しい投稿行のhtml全体が構文エラーです。ただし、すべての html を削除して、実際の投稿のテキストだけを html の代わりに表示すると、エラーが発生します。
これはJavaScriptです:
$('body').on('click','.submit_feed',function () {
var post = $("#feed_content").val();
var hidden_id = $("#hidden").val();
$("#loading").fadeIn("slow");
if( content.length < 4)
{
$.ajax({
url: "http://localhost/matthew/xaos/users/ajax/feed",
type: "POST",
data: {
parent: hidden_id,
content:post
},
cache: false,
success: function (data) {
$('#feed_error').html($(data).hide().fadeIn('slow'));
$("#loading").fadeOut("slow");
}
});
$("#loading").fadeOut("slow");
}
else
{
$('#feed_error').remove();
$.ajax({
url: "http://localhost/matthew/xaos/users/ajax/feed",
type: "POST",
data: {
parent: hidden_id,
content:post
},
cache: false,
success: function (data) {
$('#feed').prepend($(data).hide().fadeIn('slow'));
$("#loading").fadeOut("slow");
$("input[type='text']").val('');
}
});
}
return false;
});
ご覧のとおり、データベースにデータを挿入して html を返す users/ajax/feed との対話を要求します。
これは私が使用するphpです:
$return['user'] = user_lib::find_user($this->user['user_id']);
$return['content'] = $this->input['content'];
if( isset( $this->input['content'] ) )
{
if( strlen( trim( $this->input['content'] ) ) < 4 )
{
print '<h6>Post must be more than 4 characters</h6>';
exit();
}
$previous_feed = $this->db->fetch_row("select feed_id from user_feed order by feed_id desc");
if( ! $previous_feed )
{
$previous_feed['feed_id'] = 0;
}
$insert['feed_id'] = $previous_feed['feed_id'] + 1;
$insert['feed_parent'] = $this->input['parent'];
$insert['feed_user'] = $this->user['user_id'];
$insert['feed_date'] = time();
$insert['feed_content'] = $this->input['content'];
$return['feed_id'] = $this->db->insert('user_feed', $insert );
$html = <<<HTML
<table style="border:solid 1px #d7d7d7;margin-bottom:5px;">
<tr>
<td class="row2" style="width:1%;">{$data['avatar']}</td>
<td class="row1" style="width:100%;" valign="top">
<p>{$return['user']}</p>
<p>{$return['content']}</p>
</td>
</tr>
</table>
HTML;
@header( "Content-type: text/html;charset=utf-8" );
print $html;
exit();
}
すべての html を削除して print $return['content']; を実行すると、または print $this->input['content'] ブラウザのコンソールログにエラーは発生しませんが、意図されている #feed ID にテキストを返しません。
追加情報が必要な場合はお知らせください。
何が起こっているのかについてのアイデアは大歓迎です、ありがとう!