2017-12-26 5 views
0

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <meta charset="utf-8"> 
 
\t <title>jquery examples - 4</title> 
 
\t <link rel="stylesheet" type="text/css" href="css/style2.css"> 
 
</head> 
 
<body> 
 

 
<input id="name" type="text" name=""> 
 
<input id="button" type="button" value="load" name=""> 
 
<div id="content"></div> 
 
<script type="text/javascript" src="js/jQuery.js"></script> 
 
<script type="text/javascript" src="js/selectors12.js"></script> 
 

 
</body> 
 
</html>
하지

$('#button').click(function() { 
 
var name = $('#name').val(); 
 

 
\t \t \t \t $.ajax({ 
 
\t \t \t \t \t url:'php/page.php', 
 
\t \t \t \t \t data: 'name='+name, //sending the data to page.php 
 
\t \t \t \t \t success: function(data) { 
 
\t \t \t \t \t \t $('#content').html(data); 
 

 
\t \t \t \t \t } 
 
\t \t \t \t \t 
 
\t \t \t \t }).error(function() { 
 
\t \t \t \t \t alert('an error occured'); 
 

 
\t \t \t \t }).success(function() { 
 
\t \t \t \t \t /*alert*/ 
 
\t \t \t \t \t alert('an error occured'); 
 
\t \t \t \t }).complete(function() { 
 
\t \t \t \t \t /*alert*/ 
 
\t \t \t \t }); 
 
});
나는 URL을 변경할 때 error()가 작동하지 않는

: 올바르지 않은 확장명을 가진 page.php으로 error()을 확인하고 표시하십시오.

Uncaught TypeError: $.ajax(...).error is not a function

+0

가 제대로 jQuery 라이브러리를 포함했는지 확인 CDN 다음 사용합니다. –

+0

jQuery 라이브러리가 누락되었을 수 있습니다. – Hemal

+0

기능별 스 니펫 추가 –

답변

0

어쩌면 당신은 아약스 기능이없는 JQuery와의 슬림 빌드를 사용하고 있습니다 : 그것은 말하는 오류를 표시 콘솔에서

하지만. 이 중에서 일반 버전을 다운로드하십시오. link

0

여기에서 두 가지 작업을 수행해야합니다.

먼저 아래 코드를 사용하여 Jquery 파일에 Ajax가 있는지 확인하십시오.

<script> 
    $(document).ready(function() { 
     console.log($.ajax); 
    }); 
    </script> 

이 경우 오류가 발생하면 Ajax가 없습니다. 이 경우 https://code.jquery.com/jquery-2.2.4.min.js과 같은 CDN을 가리 키도록 jquery를 변경하십시오.

다음으로 Ajax 기능을 아래로 변경하십시오. 여기에 오류를 수정하고 기능을 완료하고 중복 성공 함수를 제거했습니다.

$.ajax({ 
    url:'php/page.php', 
    data: 'name='+name, //sending the data to page.php 
    success: function(data) { 
     $('#content').html(data); 
    }, error : function(e) { 
     alert('an error occured'); 
    }, complete : function() { 
     /*alert*/ 
    } 
}); 
0

슬림 버전의 jQuery를 사용하고 있습니다. 그것은 아약스 전화를 지원하지 않습니다.

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> 
<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>jquery examples - 4</title> 
    <link rel="stylesheet" type="text/css" href="css/style2.css"> 


</head> 
<body> 


<input id="name" type="text" name=""> <input id="button" type="button" value="load" name=""> 


     <div id="content"></div> 

    <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script> 
    <script type="text/javascript" src="js/selectors12.js"></script> 

</body> 
</html> 
관련 문제