Take the 2-minute tour ×

I am making a jquery ajax call to validate the input text data. When I enter value "alert()" inside the input text box, the ajax call is not made at all. And the control directly goes to the success section.

    var myScript='alert()';
      url: '<%=request.getContextPath()%>/ext/scriptTestServ',
      data: {
         script: myScript
                  alert('no error');
       error: function(jqXHR, textStatus, errorThrown){ 
                 alert('error occured');

please help

share|improve this question
What you mean when saying "fails"? –  Ionică Bizău Jul 1 '13 at 19:07
Try to check the response returning from server. in error callback, you can see textStatus. Try alert(textStatus); and also write alert(jqXHR.responseText); –  sedran Jul 1 '13 at 19:13
ajax call fails means that the call is never made –  Parag Phadtare Jul 1 '13 at 19:14
Did you bind this do $(document).ready()? The url is ok? Check the console > network tab for errors (ctrl + shift + C in chrome ). –  Fernando Jul 1 '13 at 19:19
I think you're sending javascript to the server...did you want to do that? –  Fernando Jul 1 '13 at 19:26

1 Answer 1

Have you tried escaping the text?

var myScript= escape('alert()');

Then on the server you'll have to URLDecode the input.

This way you're not actually send a script over. You're still just sending over benign text.

share|improve this answer
Thanks although this has resolved the ajax issue, The page still crashes with the same exception ("Validation Error: One of the URL parameters include javascript") when I submit it to save the data. –  Parag Phadtare Jul 1 '13 at 21:22
I noticed that the issue specified in the comment above occurs only when I enter an opening bracket or both opening and closing brackets after the word alert –  Parag Phadtare Jul 1 '13 at 21:34

Your Answer


