简体   繁体   中英

Jquery callback does not recognize jquery function call

I have a javascript function making a AJAX get request and the callback setup to update the content of a div. The only problem is that within the callback function I get the error Uncaught TypeError: Object #HTMLDivElement has no method 'html'

For some reason the jquery $("selector") is returning just the div not a jquery object.

Here's the code

//HTML
<select id="dimensions" name="dimensions" onchange="getDimention()">
    <option value="default">Select One</option>
....
</select>
 <div id="dim" > No Dimentions added yet</div>

//JS
function getDimention() {
   var eSelect = document.getElementById('dimensions');
  server.Dimention(eSelect.value, onGetDimentionSuccess); //make AJAX call
}
function onGetDimentionSuccess(response) {
   $('dim').html(response);
}

您需要使用适当的类似CSS的选择器:

$('#dim').html(response);

我想你的意思是-您忘记了ID选择器的#

$('#dim').html(response);

Id has to be appended with a #

Try this

$('#dim').html(response);

ClassNames with a .

 $('.dim').html(response); // Id dim was a class name

Do you have prototype or any other javascript framework running?

Try jQuery.noConflict() and then using jQuery('#dim').html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM