1

if i have + symbol in comment variable record is not submitted. is there any way i can encode the query string in jquery? i tried some of the methods but they didn't worked

$.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');
     }
});
Salman
  • 1,380
  • 7
  • 25
  • 41

1 Answers1

1

You need to encode your data as URL.

Check the related post : Encode URL in JavaScript?

Or pass your data as JSON object :

$.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');
     }
});
Community
  • 1
  • 1
sdespont
  • 13,915
  • 9
  • 56
  • 97