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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744917672a4600935.html
评论列表(0条)