0

Are we able remove completely all kind of encoding/default encoding on jquery ajax call ? Fyr, javascript code :

function callServer()
    {
        debugger;
        var uncompressed64Data = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wCEAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4pLSwzOko+MzZGNy"
        alert(uncompressed64Data.length);
        var compressed = LZString.compressToUTF16(uncompressed64Data);
        //alert('compressed Length : ' + compressed.length);
        var pCurrentPage = 'Prabhu';
        /* var formData = "img="+compressed+"&CurrentPage="+pCurrentPage.toString(); */
        jQuery.ajax({
            url : "/RegisterServlet_2/servlet/Register",
            type : "POST",
            contentType : "application/x-www-form-urlencoded;charset=ISO-8859-15",
            data : {
                img : compressed,
                CurrentPage : pCurrentPage,
            },
            cache : false,
            async : false,
            success : function()
            {
            },
            error : function()
            {
            }
        });
    }

Fyr, above call I make and I can able to see the request body always encoded. As per application I dont want encoding and the chars should reach the server without any encoding?

Thanks in advance!

1 Answer 1

1

This is because of content type.

Normally when a <form> uses the HTTP method POST then the form values are URL Encoded and placed in the body of the reqeust. The content type header looks like this:

content-type: application/x-www-form-urlencoded

You can simply use different content type

content-type: application/json

or

content-type: text/xml

I f you don't want json/xml, use plaine text

content-type: text/plain
Sign up to request clarification or add additional context in comments.

1 Comment

Tried already!!. See, if we that Jquery by default encode! we can see that in browser dev tool. the problem with encoding is the request body increased and so the transfer bandwidth

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.