.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?
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() }
});
Chetan 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"