Ajax call fail when I can trying to pass the special characters as data..
This is the code I am using to add a comment using Ajax call.
- <html>
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.css" />
- <script type="text/javascript" charset="utf-8" src="js/cordova-1.5.0.js">
- </script>
- <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
- <script src="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.js"></script>
- <script src="js/global.js" type="text/javascript"></script>
- </head>
- <script>
- var msgId = window.localStorage.getItem("clickedId");
- processLogInData = function(){
- var comment = ($("#comment").val());
- temp = 'messageId=' + msgId +'&';
- temp += 'uniqueId=' + device.uuid + '&';
- temp += 'comments=' + comment;
- alert(temp);
- var s= global1 +"rest/Comment/createCommentBO?"+temp;
- $.ajax({
- url:global1 +"rest/Comment/createCommentBO?",
- data: temp,
- dataType: 'xml',
- contentType:'application/x-www-form-urlencoded',
- timeout: 10000,
- async: false,
- cache: false,
- type: 'POST',
- success: function(data){
- if($(data).find("isException").text() == "false")
- {
- onTrue();
- }
- else
- {
- onFalse();
- }
- },
- error:function(XMLHttpRequest,textStatus, errorThrown) {
- alert("Error message :"+XMLHttpRequest.responseXML);
- $("#messagelist").append( XMLHttpRequest.responseXML);
- }
- });
- }
- function onTrue(){
- location.replace("comments.html");
- }
- function onFalse()
- {
- console.log("onFalse Method");
- alert("Unable to create Comment!");
- }
- function cancel(){
- location.replace("comments.html");
- }
- </script>
- <body>
- <div data-role="page" data-theme="a">
- <div data-theme="a" data-role="header">
- <img src="images/logo_header.png" alt="Orange"/>
- </div>
- <div data-role="content">
- <form method="post" name="login" data-ajax="false">
- <label for="textarea"><h3><u>Add Comment</u> : </h3></label>
- <textarea cols="15" rows="15" name="textarea" id="comment"></textarea>
- </form>
- <div>
- <div class="ui-block-a"><button type="submit" data-theme="d" onclick="cancel();" data-mini="true" data-icon="delete">Cancel</button></div>
- <div class="ui-block-b"><button type="submit" data-theme="a" onclick="processLogInData();" data-mini="true" data-icon="check" >Submit</button></div>
- </div>
- </div>
- </div>
- </body>
- </html>
When I enter special character as content as pass it to Ajax call I am getting an error :( Ajax call works fine with out any special characters... Is there any way to encode the data before passing it to ajax call???Please help me on this...
Thanks in advance.