开发者

ASP.NET multiline textbox issue with javascript and AJAX (Jquery)

开发者 https://www.devze.com 2023-01-06 17:10 出处:网络
In my web application I have a textbox called \"Address\" which is multiline and have 3 rows and 250 characters.

In my web application I have a textbox called "Address" which is multiline and have 3 rows and 250 characters.

I am calling a javascript function in which i am calling AJAX to send the data to a webservice for some processing but AJAX is unable to process variable which contains multiline text.

I am reading multiline textbox value like this in javascript function.

var puid = document.getElementById('<%=userid.ClientID%>').value;
var paddress = document.getElementById('<%=xaddress.ClientID%>').value;

and passing like this.

$.ajax({
    type: "POST",
    url : "DataService.asmx/UpdateProfile",
    data: "{'puserid': ' " + puid +   'padd': ' " + paddress +  " '}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: OnSuccess,
    error: OnError
});

If I comment paddr开发者_开发技巧ess parameters in ajax "data:" it works fine other wise ajax goes on "OnError" ...Oh i just figured out that my address has 'B' Area (apostrophe) in it thats why it its giving this problem. So how to parse apostrophe as textbox value and read in javascript variable and write back in database similary.


I'd use the jQuery Post function instead. Your GET request URIs shouldn't have new line chars in them.


var puid = document.getElementById('<%=userid.ClientID%>').value;
var paddress = document.getElementById('<%=xaddress.ClientID%>').value;

puid  => string value 
paddress => string value 

$.ajax({
  type: "POST",
  url : "DataService.asmx/UpdateProfile",
  data: {'puserid': puid  , 'padd': paddress },  need = >"," 
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: OnSuccess,
  error: OnError
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号