JSON 및 jQuery (.toJSON
함수로 래핑 됨)를 통해 AJAX 및 POST 요청을 통해 내 서버로 보내는 텍스트 필드가 있습니다. PHP 쪽에서 나는 json_decode
을하고있다.POST의 JSON/PHP에서 앰퍼샌드
모든 것이 작동하지만 앰퍼샌드 (&)를 넣으면 POST 매개 변수가 PHP 쪽에서 불완전 해집니다 (적어도 var_dump($_POST)
은 쓰고 있습니다).
toJSON과 json_decode가 모든 작업 (이스케이프 처리)을 수행하지 않아야합니까? encodeURIComponent
, & to &
, & to \u0026
을 시도했지만 작동하지 않습니다.
내가 뭘 잘못하고있어?
AJAX 호출
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;
}
}
코드를 표시하면 도움이됩니다. – Quentin
'getDataParams()'를'function getDataParams() {return (this.data === undefined)로 변경 하시겠습니까? null : 'data ='+ encodeURIComponent ($. toJSON (this.data)); }'그리고 그것은 작동해야합니다 ... – DaveRandom