Jquery ajax encoding data

前端 未结 2 1033
谎友^
谎友^ 2021-01-02 23:50

I have this code (below)..

$.ajax
({
    type: \"POST\",
    url: \"../WebServices/Feedback.svc/sendfeedback\",
    dataType: \'json\',
    async: false,
            


        
相关标签:
2条回答
  • 2021-01-03 00:28

    Is the web service belong to you or do you use someone else's web service? What was the reason the web service is not accepting (, / ? : @ & = + $ #)?

    jQuery $.ajax default contentType is application/x-www-form-urlencoded which mean jQuery will encode the content. However, since you have specify different contentType, the data is not encoded thus you have to do your own encoding.

    Alternatively, you could try to remove the contentType option and pass in your content normally (without encodeURICompnent).

    $.ajax
    ({
        type: "POST",
        url: "../WebServices/Feedback.svc/sendfeedback",
        dataType: 'json',
        async: false,
        data: '{"stars": "' + stars + '", "rating" : "' + rating + '", "note" : "' + note + '", "code" : "' + code + '", "permission" : "' + permission + '"}',
    });
    
    0 讨论(0)
  • 2021-01-03 00:46

    pass data thru as an object instead of a string:

    $.ajax
    ({
    ...
    data: {stars: stars, rating: rating...(etc)}
    });
    
    0 讨论(0)
提交回复
热议问题