XML : Passing value in URL generates error in JQuery ajax

I'm using JQuery's $.ajax() to communicate with server. I'm passing the value of a textbox which was copied from MS Word. So it may contain XML tags. And that's the problem... If I'm passing the variable to URL

  var url = "someUrl&param1=encodeURIComponent(val1)&param2=encodeURIComponent(val2)..."    

I will receive the following error message in Firefox:

  not well-formed    

and the following in IE:

  XML5610: Quote character expected. Line: 6, Column 20    

But if I'm passing the value via Ajax's data it is okay:

  $.ajax({      data: {          'param1' : val1,          'param2' : val2          ...      }  });    

I will not have error message. But why is this happening? The same data is passed to Ajax. I tried to set the contentType and dataType but it is not working when I'm passing values in Url.

So how to avoid the error messages when passing values in the Url?

No comments:

Post a Comment