코드를 테스트 한 결과 콘솔에서 "Uncaught TypeError : 속성을 'Undefined"의 LowCase'오류로 읽을 수 없습니다. "오류가 발생했습니다. 그러나 ajax()
메서드로 오류를 트리거 할 수있었습니다.
코드가 작동하지 않는 이유는 $(this)
이라는 사실은 window
과 같으며 #sum
요소가 아닙니다. six fingered man 그의 답변에서 이것을 설명했다.
대신이 코드를 사용해보십시오. 당신의 시험 즐거움을 위해
// Switch 'keydown' to 'on' and include 'keyup' event to get the actual data;
// The 'on' method allows you to "string" events together. 'keyup keydown click focus...' etc.
$('#sum').on('keyup', function(){
// Define a variable to make calling 'this' easier to write;
var me = $(this);
// Get the value of "me";
var val = me.val();
// Relay the value to the function;
updateResultPrice(val);
});
// The function, updateResultPrice, accepts an argument of "value";
function updateResultPrice(value) {
// Your prior code used $(this).val() within the function;
// The function doesn't have a $(this) to retreive the value from it,
// So, use the "value" argument;
$.ajax('/payment/summ', 'price=' + value); // Call "$.ajax", not "ajax";
// The above snippet will trigger a 404, should the file not exist.
// Just to test that it works, log it to the console;
console.log('the price is: '+value);
}
, 여기에 위의 코드의 JSFiddle 데모입니다.
게시 한 코드에'toLowerCase' 호출이 없습니다. – Pointy
분명히 정의되지 않은 변수에 .toLowerCase()를 적용하는 jQuery 코드에서 오류가 발생하기 때문입니다. – Bobort