Salman
Salman

Reputation: 1380

+ in ajax query string

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');
     }
});

Upvotes: 1

Views: 1158

Answers (1)

sdespont
sdespont

Reputation: 14025

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');
     }
});

Upvotes: 1

Related Questions