.ajax({
type: 'POST',
url: '..serverices/ajaxserver.asmx',
data: 'lname='+ $('#lastname').val()
}); return false;
if #lastname has a single quote, it throws an error. How to handle it?
.ajax({
type: 'POST',
url: '..serverices/ajaxserver.asmx',
data: 'lname='+ $('#lastname').val()
}); return false;
if #lastname has a single quote, it throws an error. How to handle it?
Share Improve this question asked Mar 26, 2010 at 17:44 JangoJango 5,55514 gold badges59 silver badges63 bronze badges3 Answers
Reset to default 6Chetan is right on—jQuery handles that for you. But, it's worth mentioning the JavaScript escape()
function, which is pretty simple:
>>> "O'Malley"
"O'Malley"
>>> escape("O'Malley")
"O%27Malley"
Don't built the query string yourself when jQuery can do it for you
data: {"lname" : $('#lastname').val()}
You can use the pair format like this:
$.ajax({
type: 'POST',
url: '..serverices/ajaxserver.asmx',
data: { "lname" : $('#lastname').val() }
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743753248a4501289.html
评论列表(0条)