skip to Main Content

I have an issue with JQuery. We are entering test% in the textfield and called one function on save button.In this function we are serialzing the form data and called AJAX then at server side it is coming as test%. It is HTML code for %

Could you please help me to resolve the same. I am not able to understand how this is coming.
Below is the code.

function onSave(thisHref)
{
  var respData = "";
  var id = $("#id").attr("value");
  var params = $("#form_used").serialize()+"&ajaxAction=SaveHeader"+"&id="+id;
  $.post(ajaxURL, params, function(data){
    if(data.length >0) 
    {
      respData = data.substring(data.indexOf("|")+1, data.lastIndexOf("|"));
    }
  }).complete(function(){ 
    if (respData.length > 0)
    {
      var responseData = respData.split("|");
      var status = responseData[0];
      var msg = responseData[1];
      if (status == 'SUCCESS')
      {
        showSuccessMsgHeader(msg);
      }
      else if (status == 'ERROR')
      {
        showErrorMsgsOnly(msg);
      }
    }
  });

}

2

Answers


  1. use .serializeArray() instead of serialize() function

    Login or Signup to reply.
  2. Use jquery’s escape & unescape method
    Try this

    <!DOCTYPE html>
    <html>
    <body>
    
    <script>
    
    var str="Hello test&#37;!";
    var str_esc=escape(str);
    document.write(unescape(str_esc))
    
    </script>
    
    </body>
    </html>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search