admin管理员组文章数量:1405516
I'm using ajax() to send POST request to a php page. This is the code:
date = $.trim($('#date').val())
expiry = $.trim($('#expiry').val())
priority = $.trim($('#priority').val())
note = $.trim($('#note_text').val())
$.ajax({
type: "POST",
url: "client?method=addNote&id=10",
data: "date="+date+"&expiry="+expiry+"&priority="+priority+"¬e="+note,
success: function(msg){
alert(msg);
}
});
my problem is that the last variable named note could has many "strange" characters, like: & % $ / : ; , .
I have seen that the php page is no receiving all the "note" string correctly. If it found (&) it js "truncate" the string. how could I encode that text?
I'm using ajax() to send POST request to a php page. This is the code:
date = $.trim($('#date').val())
expiry = $.trim($('#expiry').val())
priority = $.trim($('#priority').val())
note = $.trim($('#note_text').val())
$.ajax({
type: "POST",
url: "client?method=addNote&id=10",
data: "date="+date+"&expiry="+expiry+"&priority="+priority+"¬e="+note,
success: function(msg){
alert(msg);
}
});
my problem is that the last variable named note could has many "strange" characters, like: & % $ / : ; , .
I have seen that the php page is no receiving all the "note" string correctly. If it found (&) it js "truncate" the string. how could I encode that text?
Share asked Oct 19, 2011 at 10:25 DailDail 4,62816 gold badges77 silver badges113 bronze badges2 Answers
Reset to default 4Don't pass a string, just pass the data.
data: { date: date, expiry: expiry, priority: priority, note: note },
If you were to pass a string, then you are building a URI by hand and that has nothing to do with jQuery, so you would use encodeURIComponent.
Try:
note = encodeURIComponent($.trim($('#note_text').val()));
See here for more on encodeURIComponent
: https://developer.mozilla/en/JavaScript/Reference/Global_Objects/encodeURIComponent
本文标签: javascriptHow to encode text using jqueryStack Overflow
版权声明:本文标题:javascript - How to encode text using jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744917672a2632095.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论