5

コメントをポーズするjqueryajaxコードを作成しました。

function PostComment()
{

   $.ajax({
         type :"POST",
         url:PageUrl+'Post_LectureComment',
         data:"{Comment:'"+$('#txt_PostComment').val()+"',LectureID:'"+87+"',CategoryID:'"+2+"',Author_Id:'"+ 78+"' }",
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success:SuccessHandler ,  
         });

         function SuccessHandler(data)
         {}
}

=durgesh'raoのように'を使用してtxt_PostCommentでデータを送信すると、エラーが表示されます

ペイロードのリクエスト:{コメント:'durgesh' rao'、LectureID: '1250'、CategoryID: '2'、Author_Id: '135'}

'???でデータを送信する方法はありますか?

4

3 に答える 3

5

文字を含む JSON オブジェクトを作成しようとしていると思います'。したがって、この問題を解決するには、最初に文字列を処理する必要があります'

function replacequote(text) {
    var newText = "";
    for (var i = 0; i < text.length; i++) {
        if (text[i] == "'") {
            newText += "\\'";
        }
        else
            newText += text[i];
    }
    return newText;
};


function PostComment()
{
   $.ajax({
         type :"POST",
         url:PageUrl+'Post_LectureComment',
         data:"{Comment:'" + replacequote($('#txt_PostComment').val()) + "',LectureID:'"+87+"',CategoryID:'"+2+"',Author_Id:'"+ 78+"' }",
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success:SuccessHandler ,  
         });

         function SuccessHandler(data)
         {}
}
于 2013-02-25T10:42:07.600 に答える
1

文字列リテラルを使用してオブジェクトを作成する必要はありません。新しいオブジェクトを作成し、適切なプロパティを設定するだけです。

$.ajax({
         type :"POST",
         url:PageUrl+'Post_LectureComment',
         data:{comment: $('#txt_PostComment').val(),lectureID:"87",categoryID:"2",author_Id:"78"},
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success:SuccessHandler  
         });
于 2013-02-25T10:31:04.227 に答える
0

クエリを編集できます。
あなた'が問題の作成者であるため、検索中に次のようなクエリを作成できます。

SET ESCAPE "'"
SELECT * FROM x_table WHERE txt_PostComment with ' like "%durgesh'rao%";
于 2013-02-25T10:50:55.623 に答える