Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 
avatar of employee-0

employee-0

employee-0 has asked 3 questions and find answers to 1 problems.

Stats

48
EtPoint
12
Vote count
3
questions
1
answers

About

Links http://javascript.crockford.com/remedial.html

Team Beta ( Special Projects Lead )

  • Matrix Notation - A simplified version of JSON for matrix data written in a compiled language. Faster by by about 10% due to reduced overhead.

  • ImageEncode - Removes the 33% overhead associated with Base64.


if POST data is sent in the body of a request, why use URL encoding? Is there something mro

POST requests require a contentType to be set to describe the data being sent in the body of the request.

GET requests do not as there is no body. The request parameters are in the URL.

Here is how this looks in code ( works fine ).

/******************************************************************************/
// AJAX

    $P.ajax = function (config_ajax) {
        var xhr;

        // get

        if (config_ajax.type === 'get') {
            xhr = new win.XMLHttpRequest();
            xhr.open('GET', config_ajax.url, true);
            xhr.onload = function () {
                if (this.status === 200) {
                    config_ajax.callback(xhr.responseText);
                }
            };
            xhr.send(null);
        }

        // post

        if (config_ajax.type === 'post') {
            xhr = new win.XMLHttpRequest();
            xhr.open("POST", config_ajax.url, true);
            xhr.setRequestHeader("Content-type",
                    "application/x-www-form-urlencoded");
            xhr.onload = function () {
                if (this.status === 200) {
                    config_ajax.callback(xhr.responseText);
                }
            };
            xhr.send(config_ajax.data);
        }

Here you can see the send data for GET is null and the send data for POST is populated and also that the POST data is url encoded ( just what I'm using ) and the GET data is not.

url encoding is not default as if you do not specify it or some other encoding, an error will be thrown.

I guess, what I'm asking, is why can't I leave it off ( the contentType for POST ) and have the data transfer?