2012-08-09 5 views
0

이것은 Ajax 호출을 사용하여 주석을 추가하는 데 사용하는 코드입니다.데이터로 특수 문자를 전달하려고 할 때 Ajax 호출이 실패합니다.

<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; 
       var s= global1 +"rest/Comment/createCommentBO?"+temp; 

       $.ajax({ 
        url:global1 +"rest/Comment/createCommentBO?", 
        data: temp, 
        dataType: 'xml', 
        timeout: 10000, 
        async: false, 
        cache: false, 
        type: 'POST', 
        success: function(data){ 
         if($(data).find("isException").text() == "false") 
         { 
          //alert('No Exceptions found'); 
                   onTrue(); 

         } 
         else 
         { 
          onFalse(); 
         } 
        }, 
        error:function(XMLHttpRequest,textStatus, errorThrown) { 
           // alert("Error status :"+textStatus); 
           // alert("Error type :"+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> 
내가 오류 :(아약스 호출에 특수 문자가 밖으로 잘 작동 무엇입니까 전화 아약스로 전달과 같은 내용으로 특수 문자를 입력

... 인코딩하는 방법은 없나요 데이터 아약스 호출에 전달하기 전에하는 것은 ???. 미리 ... 이것에

답변

0

(1.)

감사를 도와 하나는 양식에 데이터를 넣고 직렬화하고 보내야하세요 서버에 연결 (2) 초 당신은 js inbuilt 함수 인 encodeURIComponent()를 사용할 수 있습니다.

관련 문제