asp.net - how to handle single quote in $.ajax POST (JQuery)? - Stack Overflow

.ajax({type: 'POST',url: '..servericesajaxserver.asmx',data: 'lname='+ $

.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 badges
Add a ment  | 

3 Answers 3

Reset to default 6

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"

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信