나는 미쳐 가고 있습니다. 이유는 모르겠지만 매우 간단한 Jquery 게시가 제대로 작동하지 않습니다. 아래와 같이 index.php와 temp.php가 있습니다. 나는 여전히 "OK"를 반환하지 않고, if 조건 전에 경고한다면 데이터가 "ok"를 반환하기 때문에 왜 그런지 알지 못합니다.JQuery 게시가 올바르게 작동하지 않습니다.
의 index.php : 어떤 아이디어에 미리
<? session_start(); ?>
<!DOCTYPE HTML>
<meta charset="windows-1250">
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery- ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"> </script>
<link rel="stylesheet" type="text/css" href="style.css" />
<script>
function do_post(item)
{
$.post("temp.php", {par:item}, function(data,status){
//alert("Data: " + data + "\nStatus: " + status);
if(data=="ok")
{
alert('RETURNED OK');
//location.reload();
}
else
{
alert('NOT RETURNED OK');
}
});
}
</script>
<body>
<a href="#" onclick="do_post('whatever');">click</a>
</body>
</html>
temp.php:
<? echo "ok"; ?>
감사합니다. 당신은 단순히 당신의 PHP 스크립트에 echo'ing하는 경우
$.post("temp.php", {par:item}, function(){}, 'text');
을 : 나도 다시 기대 .post jQuery를 말해 명시 적으로 적절한 응답 헤더 콘텐츠 형식을 사용하여 응답 JSON을 사용하거나 제안
'data'는 보이지 않는 문자를 포함 할 수 있습니다. –
그가 경고 (데이터)를하면 그는 'ok'로 돌아옵니다. – Rell
@EvanMulawski가 맞을지도 모릅니다. 이것을 시도하십시오 : if (data) 문 앞에 'console.log (typeof data, data.length)'를 추가하고 콘솔이 반환하는 것을 알려주십시오. –