abstrait:jquery與ajax獲取特殊字符在用jquery加ajax寫的時候,發(fā)現(xiàn)如果傳進去的數(shù)據(jù)包含&則無法獲取數(shù)據(jù)而+號的話就會被判定為空,解決辦法就是使用encodeURIComponent()函數(shù)對要發(fā)送的數(shù)據(jù)進行編碼.function ajax() { $val = encodeURIComponent($('#no
jquery與ajax獲取特殊字符
在用jquery加ajax寫的時候,發(fā)現(xiàn)如果傳進去的數(shù)據(jù)包含&則無法獲取數(shù)據(jù)而+號的話就會被判定為空,解決辦法就是使用encodeURIComponent()函數(shù)對要發(fā)送的數(shù)據(jù)進行編碼.
function ajax() { $val = encodeURIComponent($('#note').val()); $.ajax({ type: 'post', url: 'xxx.php', data: 'txt=' + $val, success: function(data) { $("#remove").empty(); $("#main").html(data); $(".chg_area").hide(); } }); };
這樣就能傳&+這些特殊符號了
更多關(guān)于jquery與ajax獲取特殊字符實例詳解請關(guān)注PHP中文網(wǎng)(ipnx.cn)其他文章!