IT,프로그래밍/신비한 오류 사전

jquery-1.12.4.min.js:4 Uncaught TypeError: Illegal invocation 오류

Jquey 를 이용해서 ajax 요청을 하던중 처음보는 에러를 만났다.

jquery-1.12.4.min.js:4 Uncaught TypeError: Illegal invocation
    at e (jquery-1.12.4.min.js:4)
    at dc (jquery-1.12.4.min.js:4)
    at dc (jquery-1.12.4.min.js:4)
    at dc (jquery-1.12.4.min.js:4)
    at Function.n.param (jquery-1.12.4.min.js:4)
    at Function.ajax (jquery-1.12.4.min.js:4)
    at password_reset (company.js?upt=1.54.200203:60)
    at HTMLButtonElement.onclick (get_company:1)

위의 오류를 구글링 해보니

 

https://stackoverflow.com/questions/11071100/jquery-uncaught-typeerror-illegal-invocation-at-ajax-request-several-eleme

stack overflow 에서 글을 발견할수 있었다.

 

그 중 가장많이 like 를 받은 해결책은 아래와 같았다

 


Thanks to the talk with Sarfraz we could figure out the solution.

The problem was that I was passing an HTML element instead of its value, which is actually what I wanted to do (in fact in my php code I need that value as a foreign key for querying my cities table and filter correct entries).

So, instead of:

var data = {
        'mode': 'filter_city',
        'id_A': e[e.selectedIndex]
};

it should be:

var data = {
        'mode': 'filter_city',
        'id_A': e[e.selectedIndex].value
};

Note: check Jason Kulatunga's answer, it quotes JQuery doc to explain why passing an HTML element was causing troubles.

 


여기서 포인트는 I was passing an HTML element instead of its value 였는데.

 

내 소스를 확인을 해본결과

... password_reset(${obj_com.id});">비밀번호 리셋</button></td>

이렇게 되어 있었다.

 

혹시 답을 찾으셨는지 모르겠다. 답은

... password_reset('${obj_com.id}');">비밀번호 리셋</button></td>

이었다.

 

바로 ' ' 을 안써주었기 때문에 파라미터로 문자열이 아닌 변수가 날라갔던것이다.

 

 

멍청한 내 자신에게 건배... (또륵)