Ampersand in JSON/PHP in POST

Posted by svenkapudija on Stack Overflow See other posts from Stack Overflow or by svenkapudija
Published on 2012-06-03T22:34:24Z Indexed on 2012/06/03 22:40 UTC
Read the original article Hit count: 194

Filed under:
|
|
|
|

I'm having a text field which is send via JSON and jQuery (wrapped with .toJSON function) to my server via AJAX and POST request. On PHP side I'm doing json_decode .

Everything works but if I put ampersand (&) inside it splits up the POST parameter so its incomplete on PHP side (at least what var_dump($_POST) is writing out).

Shouldn't the toJSON and json_decode do all the job (escaping)? I tried encodeURIComponent, & to &, & to \u0026 and it's not working.

What I'm doing wrong?

AJAX call

function execute() {
        this.setupUrl();
        return $.ajax({
            type: this.requestMethod,
            data: this.getDataParams(),
            url: this.url
        });
    }

function getDataParams() {
            if(this.data != undefined) {
                if(this.requestMethod == 'POST' || this.requestMethod == 'PUT') {
                    return "data=" + $.toJSON(this.data);
                } else if (this.requestMethod == 'GET') {
                    return this.data;
                }
            } else {
                return null;
            }
        }

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery