//alert() shows values in a popup window alert("js is working");JavaScript에 중요한 구문 오류가 있으면 전혀 실행되지 않기 때문에 코드가 실제로 실행되는지 확인하는 데 경고를 사용할 수 있습니다. 특정 코드 블록 또는 세그먼트에 도달하는지 확인하는 데 사용될 수도 있습니다.
//console.log() shows values in the firebug console window var x = ... etc console.log(x);Console.log ()는 루프에서 실행 된 값을 표시하고 이벤트를 잡는 데 매우 유용 할 수 있습니다. 나중에 게시물에서 더 자세히 설명하십시오. 로깅을위한 전체 범위의 옵션은 Firebug Console API Wiki 페이지에서 볼 수 있습니다. . 중요 : Firebug 명령을 동봉하십시오. 그렇지 않으면 jQuery 코드가 콘솔이 열릴 때만 작동합니다.
//try catch example 1 try { $("#user").focus(); } catch(err){ return false; } //try catch example 2 try { var tmp = doSomething(); if (tmp == something.errorCondition) throw new Error("Error condition in X"); } catch(err) { //handle ((err && err.message) || err.toString()) } //try catch example 3 try { // code that may cause an error } catch (e) { // deal with error (or not) } // code that runs whether or not error occurred
jQuery.error = console.error;
$("#createContact").click(function () { //Attach a click event handler to the button var form = $("form"); //Grab the form element from the DOM $.ajax({ type: "POST", //The type of HTTP verb (post, get, etc) url: form.attr( "action" ), //The URL from the form element where the AJAX request will be sent data: form.serialize(), //All the data from the form serialized dataType: "json", //The type of response to expect from the server success: function ( data, statusCode, xhr ) { //Triggered after a successful response from server if ( data && data.Message ) { alert( data.Message ); } }, error: function ( xhr, errorType, exception ) { //Triggered if an error communicating with server var errorMessage = exception || xhr.statusText; //If exception null, then default to xhr.statusText alert( "There was an error creating your contact: " errorMessage ); } }); return false; //Ignore the default behavior of the button click }); [code lang="php"]Firebug 확인 jQuery 오류 유형을 결정하는 데 사용할 수있는 Statustext 필드가 있습니다.
function ajaxError(request, type, errorThrown) { var message = "There was an error with the AJAX request.n"; switch (type) { case 'timeout': message = "The request timed out."; break; case 'notmodified': message = "The request was not modified but was not retrieved from the cache."; break; case 'parseerror': message = "XML/Json format is bad."; break; default: message = "HTTP Error (" request.status " " request.statusText ")."; } message = "n"; alert(message); }추가 읽기 :
jQuery 오류 관리에서 .ajaxerror () 메소드의 역할은 무엇입니까? 모든 요소에 첨부 될 수 있지만 일반적으로 문서에 첨부됩니다. 이 방법은 글로벌 오류 처리에 매우 유용 할 수 있습니다. 예를 들어 AJAX 요청이 실패 할 때 메시지를 표시하는 데 사용될 수 있습니다.
Try-Catch 문은 오류 처리에 jQuery에서도 사용할 수있는 JavaScript 기능입니다. 이를 사용하여 코드 블록을 "시도"하고 발생하는 오류를 "잡아"할 수 있습니다. 이것은 예외를 제외 할 수있는 예측할 수없는 코드를 처리 할 때 특히 유용 할 수 있습니다.
} catch (error) {
// 오류가 발생하는 경우 실행되는 코드
}
jquery (jquery)의 방법을 제공 할 수있는 방법은 무엇입니까?
Ajax 오류. 상태 코드 옵션을 사용하여 특정 HTTP 상태 코드에 대한 콜백 함수를 정의 할 수 있습니다. 예를 들어, 404 상태 코드 (발견되지 않음) :
$. ajax ({
atsterscode : {
404 : function () {
alert ( 'page find'); .fail () jQuery에서 오류 처리를위한 메소드?
// ajax 옵션
}). 실패 (function () {
// 요청이 실행되면 실행되면 코드
try {
var data = $ .parsejson (응답);
$. ajax ({
timeout : 5000, // 5 초
// 다른 ajax 옵션
}). 실패 (function () {
// 타임 아웃이 발생하면
플러그인?
부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.
Copyright© 2022 湘ICP备2022001581号-3