programing

jQuery "정의되지 않은 속성 'defaultView'를 읽을 수 없습니다" 오류

itmemos 2023. 9. 9. 09:04
반응형

jQuery "정의되지 않은 속성 'defaultView'를 읽을 수 없습니다" 오류

저는 jQuery를 사용하여 단순히 작동 여부에 따라 1/0을 반환하는 PHP 파일에 양식 필드를 게시하고 있습니다...

코드의 추출:

$.ajax({
    url: "ajax/save_text.php", //Relative?!?
    //PHP Script
    type: "POST",
    //Use post
    data: 'test=' + $(this).val(),
    datatype: 'text',
    //Pass value       
    cache: false,
    //Do not cache the page
    success: function(html) {
        if (html == 1) {
            $(this).hide().siblings('span').html($(this).value).show();
                    alert("awesome!");
        } else alert('It didn\'t work!');
    },
    //Error
    error: function() {
        alert("Another type of error");
    }
});

그러나 성공할 때마다(실패 == 1) 콘솔에서 오류가 표시됩니다.

Uncatched TypeError: 정의되지 않은 'defaultView' 속성을 읽을 수 없습니다."

경고는 절대 일어나지 않을 거고...?

구글은 이 오류에 대해 많은 정보를 가지고 있지 않은 것 같고 jQuery, 원인을 누가 알고 있습니까?

왜냐하면.this전에 당신이 다루던 것이 아니라, 지금은ajaxjQuery object, 다음 옵션을 추가합니다.

$.ajax({
  context: this,
  url: "ajax/save_text.php",
  ...

이쪽입니다.this당신의 콜백 안은 같은 것을 말합니다.this전화할 때 처럼요또는, 참조를 유지합니다.this별변수로

또한, 당신은 조정할 것입니다.$(this).value, 당신 말은 아마도this.value아니면$(this).val().

언급URL : https://stackoverflow.com/questions/3936211/jquery-cannot-read-property-defaultview-of-undefined-error

반응형