2012-07-08 2 views
1

내가 변수 변수 레코드에 + 기호를 제출하지 않은 경우. jquery에서 쿼리 문자열을 인코딩 할 수있는 방법이 있습니까? 나는 몇 가지 방법을 시도했지만 효과가 없었습니다.+ 아약스 쿼리 문자열에서

$.ajax({ 
    type: 'post', 
    url: rootURL + 'services/service.php?method=insertcomment', 
    data: 'comment=' + comment+'&storyid='+storyid, 
    dataType: 'json', 
    success: function (data) { 
      if(data.code == 200) 
       $('#success-message')..show(); 
      else 
       alert('failure'); 
    } 
}); 

답변

1

데이터를 URL로 인코딩해야합니다.

확인 관련 게시물 : Encode URL in JavaScript?

또는 JSON 객체로 데이터를 전달할는 :

$.ajax({ 
    type: 'post', 
    url: rootURL + 'services/service.php?method=insertcomment', 
    data: {comment : comment, storyid : storyid}, 
    dataType: 'json', 
    success: function (data) { 
      if(data.code == 200) 
       $('#success-message').show(); 
      else 
       alert('failure'); 
    } 
}); 
+0

동의, 데이터 객체로 전달되어야한다. –

관련 문제