언제든지 "오류"가 반환됩니다.PHP는 json에서 보낸 json 보낸 데이터를 확인하거나 가져올 수 없습니다.
if($_POST){
$return="Success.";
echo json_encode($return);
}
jQuery를 : 내 코드 PHP의 index.php라는 하나 개의 파일에
function Save(){
$.ajax({
url: "./index.php",
type: "POST",
data: {
example:"example",
example2:$(".content").text()
},
dataType: "json"
}).done(function(data){
$('#response').append('<p style="color:red;">'+data+'</p>');
alert("done");
}).fail(function(){
$('#response').append('<p style="color:red;">Error</p>');
});
}
이것은 요청 된 네트워크 탭을 내가 모두가 POST와 OK라고 생각합니다. 네트워크 탭 :
"Success."<!DOCTYPE html>
<html>
<head>
<title>Text</title>
<script src="style/jquery.min.js"></script>
<script>
$(document).ready(function() {
function Save(){
$.ajax({
url: "./index.php",
type: "POST",
data: {
filename:"something.php",
text:$(".content").text()
},
dataType: "json"
}).done(function(data){
$('#response').append('<p style="color:red;">'+data+'</p>');
alert("done");
}).fail(function(){
$('#response').append('<p style="color:red;">Error</p>');
});
}
$(".content").focus(function(){
$(window).bind('keydown', function(event) {
if (event.ctrlKey || event.metaKey) {
switch (String.fromCharCode(event.which).toLowerCase()) {
case 's':
event.preventDefault();
Save();
break;
}
}
});
});
});
</script>
<style>
.content {
width: 80%;
height: 80%;
border: 1px solid #ccc;
padding: 5px;
}
</style>
</head>
<body>
<div id="response"></div>
<pre><div class="content">
<?php
if(true){
echo 'ds';
//das
}
.test {
size: 5pt;
}
</div></pre>
</body>
</html>
가 어떻게이 문제를 해결하는 방법을 말해 줄래 : 여기
Remote Address:127.0.0.1:80
Request URL:http://localhost/test/test/test/index.php
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate
Accept-Language:en-US,en;q=0.8,bg;q=0.6
Connection:keep-alive
Content-Length:606
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:_ga=GA1.1.1569762264.1406894118
Host:localhost
Origin:http://localhost
Referer:http://localhost/test/test/test/
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
example:example
example2:
<?php
if(true){
echo 'ds';
//das
}
.test {
size: 5pt;
}
Response Headersview source
Connection:Keep-Alive
Content-Length:1641
Content-Type:text/html
Date:Tue, 09 Sep 2014 20:03:46 GMT
Keep-Alive:timeout=5, max=97
Server:Apache/2.4.9 (Unix) OpenSSL/1.0.1g mod_fcgid/2.3.9 PHP/5.5.11 mod_perl/2.0.8-dev Perl/v5.16.3
X-Powered-By:PHP/5.5.11
그리고는 네트워크 탭에서 응답 탭입니까?
이 오류가 발생하면 브라우저 도구를 살펴보고받은 응답을 살펴보고 문제가 어디에 있는지 알려줍니다. – Hammerstein