구문 오류: 예기치 않은 토큰 <
여러 가지 시도를 해봤지만 방법이 없습니다.항상 이 오류는 발생합니다.합격 여부를 확인하기 위해 하나의 옵션만 사용하려고 했는데, jquery 호출이 바뀌지는 않았습니다.
이 에러에 대해 인터넷상의 여러 곳을 찾아봤지만, 그 원인을 알 수 없었습니다.PC에서 Easy를 사용하는 경우PHP는 완벽하게 동작하지만, 온라인으로 하면 동작하지 않습니다.
구문 오류: 예기치 않은 토큰 <
제 코드는 다음과 같습니다.
$(function(){
$('#salvar').click(function(){
var key = 'salvar';
var title = $('#title').val();
var opcao1 = $('#opcao1').val();
var opcao2 = $('#opcao2').val();
var opcao3 = $('#opcao3').val();
var opcao4 = $('#opcao4').val();
var opcao5 = $('#opcao5').val();
var opcao6 = $('#opcao6').val();
if(title.length > 0){
if(opcao2.length > 0){
$('#resposta').removeClass().html('Salvando a enquete...<br clear="all"><br><img src="images/switch-loading.gif" />');
$.ajax({
type : 'POST',
url : 'funcoes/enquete_adm.php',
dataType : 'json',
data: {key:key,title:title,opcao1:opcao1,opcao2:opcao2,opcao3:opcao3,opcao4:opcao4,opcao5:opcao5,opcao6:opcao6},
success : function(data){
if(data.sql == 'ok'){
$('#resposta').addClass('success-box').html('Enquete Salva!').fadeIn(1000);
$('#control').fadeOut();
}else if(data.sql == 'error'){
$('#resposta').addClass('info-box').html('Ops, aconteceu um erro. Por favor, tente novamente').fadeIn(1000);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("XMLHttpRequest " + XMLHttpRequest[0]);alert(" errorThrown: " + errorThrown);alert( " textstatus : " + textStatus);
}
});
}else{
$('#resposta').addClass('warning-box').html('É necessário no mínimo duas opções');
};
}else{
$('#resposta').addClass('warning-box').html('Coloque a pergunta da enquete');
};
return false;
});
}); // End
이 문제는 일반적으로 존재하지 않는 파일을 포함하거나 파일에 게시할 때 발생합니다.서버는 다음과 같이 둘러싸인 일반 html 형식의 "404 Not Found"를 반환합니다.
'<html></html>'
태그. 첫 번째 쉐브론<은 유효한 js도 유효한 json도 아니기 때문에 예기치 않은 토큰을 트리거합니다.
funcoes/enquete_adm을 바꾸려고 하면 어떨까요?php'를 절대 URL로 변경하시겠습니까?
편집(수년 후)
근본적인 원인은 404개의 에러에 의한 것이 아닐 수 있습니다.API에 요청을 하여 HTML 형식의 오류를 수신할 수 있습니다.API 엔드포인트가 반환되어야 하는 몇 가지 사례를 우연히 발견했습니다.
{
error: "you must be authenticated to make this request"
}
헤더 401이 있는 경우.그리고 대신 나는
<html>You must be authenticated to make this request</html>
헤더 200 포함.
을 미리수 「200」은 하지 않고, 「200」은 수 .JSON.parse
이치노
는 필요없는 것을 가지고 있다;
(오디오):
예:
}else{
$('#resposta').addClass('warning-box').html('É necessário no mínimo duas opções');
};
'';
후에}
렸습니니다다
또 다른 예는 다음과 같습니다.
}else{
$('#resposta').addClass('warning-box').html('Coloque a pergunta da enquete');
};
아마 당신의 요청에 따라 텍스트/html 인코딩을 받고 있는 것 같습니다.이 문제는 다음과 같습니다.
dataType : 'json',
변경해 보다
dataType : 'html',
http://api.jquery.com/jQuery.get/ 에서 :
dataType Type: String 서버에서 예상되는 데이터 유형입니다.디폴트:인텔리전트 게스(xml, json, 스크립트 또는 html).
「」SyntaxError: Unexpected token <
API 엔드포인트가 문서 본문에 JSON을 반환하지 않았음을 의미합니다(예: 404).
「 」, 「 」, 「 」를 수 있습니다.{
(JSON의 ')', RSA가 됩니다.<
( 목 ( ( ( ( ( )
응답 성공:
<html>
<head></head>
<body>
{"foo": "bar", "baz": "qux"}
</body>
</html>
찾을 수 없는 응답:
<html>
<head></head>
<body>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
</body>
</html>
반환된 항목을 확인하려면 브라우저에서 데이터 끝점의 URL을 방문하십시오.
비슷한 문제가 있었는데 콘솔 메시지를 표시하기 위해 javascript를 보내는 것이 문제였습니다.
(어플리케이션이 아닌) 브라우저에서 파일을 봐도 예상대로(추가 태그가 표시되지 않는 등) 표시되지만 html/text 출력에 표시되어 구문 해석을 시도하고 있었습니다.
이게 누군가에게 도움이 되길 바라!
스크립트 중 하나에 소스 맵 URL이 포함되어 있는 것 같습니다(예를 들어 Minified jQuery에는 소스 맵에 대한 참조가 포함되어 있습니다).
Chrome 개발자 도구를 열면 Chrome은 디버깅을 지원하기 위해 URL에서 소스 맵을 가져오려고 합니다.그러나 소스 맵은 실제로 서버에 존재하지 않지만 HTML이 포함된 일반 404 페이지가 전송됩니다.
이 오류는 코드에 오류가 있는 PHP 스크립트에 대한 JSON AJAX 호출에서도 발생할 수 있습니다.서버는 종종 html 마크업으로 포맷된 PHP 오류 정보를 반환하도록 설정됩니다.이 응답은 비활성 JSON으로 해석되어 "예기치 않은 토큰 <" AJAX 오류가 발생합니다.
Chrome을 사용하여 PHP 오류를 보려면 웹 인스펙터의 네트워크 패널로 이동하여 왼쪽에 나열된 PHP 파일을 클릭하고 응답 탭을 클릭합니다.
아약으로 게시할 때, 상) 천 합 을 지 하 니 는 다 withson ajax errors when posting ajax) returning ason no via, submit to를 that valid투 (고html
tags or other태그 또는 기타
<form action="path/to/file.php" id="ajaxformx">
id 값에 x를 추가하면 jquery는 이를 처리하지 않습니다.
Once you are sure everything is fine then remove the 모든 것이 정상임을 확인했으면x
부에서id="ajaxform"
and the empty the 그리고 빈칸은action
속성 값 값 값
몇 분 전만 해도 같은 에러를 정리할 수 있었습니다.
나도 저 나도 요고 있었다.syntax error: unexpected token <
아약을 통해 양식을 게시하는 동안 컬을 뭘 요.그리고 나서 컬을 사용해서 뭘 돌려주는지 봤어요.
curl -X POST --data "firstName=a&lastName=a&email=array@f.com&pass=aaaa&mobile=12345678901&nID=123456789123456789&age=22&prof=xfd" http://handymama.co/CustomerRegistration.php
나는 이런 대답을 받았다.
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/handymama/public_html/CustomerRegistration.php:1) in <b>/home/handymama/public_html/CustomerRegistration.php</b> on line <b>3</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/handymama/public_html/CustomerRegistration.php:1) in <b>/home/handymama/public_html/CustomerRegistration.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/handymama/public_html/CustomerRegistration.php:1) in <b>/home/handymama/public_html/CustomerRegistration.php</b> on line <b>7</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/handymama/public_html/CustomerRegistration.php:1) in <b>/home/handymama/public_html/CustomerRegistration.php</b> on line <b>8</b><br />
따라서 로그 수준을 경고가 아닌 오류로만 변경하기만 하면 되었습니다.
error_reporting(E_ERROR);
포함된 모든 JS 경로를 확인했습니다.
예: 변경
<script src="js/bootstrap.min.js" type="text/javascript"></script>
로.
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" type="text/javascript"></script>
코드에서 이 행을 삭제하면 문제가 해결되었습니다.
header("Content-Type: application/json; charset=UTF-8");
같은 에러가 발생했기 때문에, 매우 다른 이유로 이것을 여기에 넣습니다.
노드/익스프레스/제이드 경유로 서비스를 제공하고 있으며 오래된 옥 파일을 이식했습니다.행 중 하나는 Typekit이 실패했을 때 bork하지 않는 것입니다.
script(type='text/javascript')
try{Typekit.load();}catch(e){}
보였지만,하는 옥 에는 해한한 blocks blocks a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a가 하다는 것을 ..
:
script(type='text/javascript').
try{Typekit.load();}catch(e){}
간단하지만 까다롭다.
Java 스크립트 함수에서 false로 전달되는 매개 변수를 무시하기만 하면 됩니다.
예:
function getCities(stateId,locationId=false){
// Avoid writting locationId= false kind of statements
/*your code comes here*/
}
locationId= 잘못된 종류의 문장은 쓰지 마십시오. 그러면 크롬 및 IE에서 오류가 발생하므로
이 일은 iframe을 통해 페이지가 로드된 상태에서 발생했습니다.iframe src 페이지에는 404 스크립트 참조가 있습니다.분명히 상위 페이지에서 스크립트 참조를 찾을 수 없었기 때문에 범인을 찾는데 시간이 걸렸습니다.
jquery code가 포함되어 있지 않은지 확인합니다.
< script > </script >
그것을 삭제하면 코드는 정상적으로 동작합니다.내 경우는 동작했습니다.
시스템에서 NVM을 실행하는 경우 서버를 시작하기 전에 노드 버전을 확인해야 합니다.
언급URL : https://stackoverflow.com/questions/18561556/syntax-error-unexpected-token
'sourcecode' 카테고리의 다른 글
FTP 액세스를 제공하지 않고 WordPress 플러그인을 설치/업데이트할 수 있습니까? (0) | 2023.03.15 |
---|---|
HttpResponseMessage 콘텐츠를 텍스트로 읽는 방법 (0) | 2023.03.15 |
페이지에서 Woocommerce 주문을 쿼리하는 방법 (0) | 2023.03.15 |
교차 도메인 POST 요청이 쿠키 Ajax Jquery를 전송하지 않습니다. (0) | 2023.03.15 |
AngularJs 사전에서 ng-repeat을 사용하는 방법 (0) | 2023.03.15 |