0

I am using following code

$.post("insertPrivateMessage?action=sendchat", 
    { to: GroupUserArray[count], 
      message: message, 
      username: $("#author").val(),
      GROUP: chatboxtitle
    } , 
   function(data){
      message = message.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");
});

but when replacing message getting following error

message.replcace is not a function

is my code OK?

0

2 Answers 2

1

The message variable does not exist in the function. The object is a list of variables sent to the server, the function after it is the function run when the response comes. The message variable does not exist in that function.

I'm not sure what you are trying to do. If you are trying to replace the text before you send it to the server, then you need to use the following code:

$.post("insertPrivateMessage?action=sendchat", 
    { to: GroupUserArray[count], 
      message: message.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;"), 
      username: $("#author").val(),
      GROUP: chatboxtitle
    } , 
   function(data){
});

If you are trying to replace the data returned by the server, then you need to use this code:

$.post("insertPrivateMessage?action=sendchat", 
    { to: GroupUserArray[count], 
      message: message, 
      username: $("#author").val(),
      GROUP: chatboxtitle
    } , 
   function(data){
      message = data.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");
});
Sign up to request clarification or add additional context in comments.

Comments

0

check your web directory where you have deployed. Looks like a typo to me, my assumption would be that the javascript you have there is sitting in a cache somewhere. Try refreshing your test website or Ctrl+F5 refresh it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.