最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught Error: Syntax error, unrecognized expression: #[object HTMLDivElement] - Stack Overflow

programmeradmin17浏览0评论

I'm passing a value to codeigniter function for getting a result. But the ajax value does not pass to the php function.

My script function follows :

<script src=".11.1.min.js"></script>
<Script>
$(document).ready(function() {
$("#up").on('click',function(){
      if ($("#incdec").val() < $(this).data("max")) {
        $("#incdec").val(parseInt($("#incdec").val())+1);
        }
});

$("#down").on('click',function(){
      if ($("#incdec").val() > $(this).data("min")) {
        $("#incdec").val(parseInt($("#incdec").val())-1);
      }
 });
 });
 $(document).ready(function() {
  $(".butt").on('click',function(){
    var e=$(".aa").val();
    alert(e);

    $.ajax({
         type:"POST",
         data:"id="+e,
         url:"<?php echo site_url('pages/getit');?>",
         success: function(html){
              $('#'+dataprocess).html(html);
         }
    });
  });
});

</script>

My HTML code :

<input type="text" name="incdec" id="incdec" value="0" class="aa"/>
<input type="button" class="butt"  id="up" value="Up" data-max="5" />
<input type="button" id="down" value="Down" data-min="0" class="butt"/>

<div id="dataprocess"></div>

But I'm getting an error as follows:

Uncaught Error: Syntax error, unrecognized expression: #[object HTMLDivElement]

Please help me find my mistake.

I'm passing a value to codeigniter function for getting a result. But the ajax value does not pass to the php function.

My script function follows :

<script src="http://code.jquery./jquery-1.11.1.min.js"></script>
<Script>
$(document).ready(function() {
$("#up").on('click',function(){
      if ($("#incdec").val() < $(this).data("max")) {
        $("#incdec").val(parseInt($("#incdec").val())+1);
        }
});

$("#down").on('click',function(){
      if ($("#incdec").val() > $(this).data("min")) {
        $("#incdec").val(parseInt($("#incdec").val())-1);
      }
 });
 });
 $(document).ready(function() {
  $(".butt").on('click',function(){
    var e=$(".aa").val();
    alert(e);

    $.ajax({
         type:"POST",
         data:"id="+e,
         url:"<?php echo site_url('pages/getit');?>",
         success: function(html){
              $('#'+dataprocess).html(html);
         }
    });
  });
});

</script>

My HTML code :

<input type="text" name="incdec" id="incdec" value="0" class="aa"/>
<input type="button" class="butt"  id="up" value="Up" data-max="5" />
<input type="button" id="down" value="Down" data-min="0" class="butt"/>

<div id="dataprocess"></div>

But I'm getting an error as follows:

Uncaught Error: Syntax error, unrecognized expression: #[object HTMLDivElement]

Please help me find my mistake.

Share Improve this question edited Apr 18, 2015 at 11:05 Sepster 4,85822 silver badges39 bronze badges asked Apr 18, 2015 at 10:44 user4736598user4736598 1
  • 1 $('#dataprocess').html(html); instead of $('#'+dataprocess).html(html); – mcklayin Commented Apr 18, 2015 at 10:46
Add a ment  | 

2 Answers 2

Reset to default 4

In this bit of code:

success: function(html){
    $('#'+dataprocess).html(html);
}

you are appending a string, namely '#', to an object, dataprocess.

The object is converted to a string, '[object HTMLDivElement]', which tells its type.

Try this instead:

success: function(html){
    $('#dataprocess').html(html);
}

EDIT:

The way jquery selectors work, in this case the 'by-id' selector, you have the 'id' marker, '#', immediately followed by the id of the control you are trying to select, in this case 'dataprocess'.

Here is a useful resource about jquery selectors:

http://www.w3schools./jquery/jquery_ref_selectors.asp

Hope this helps. Cheers!

Please try this ajax as blw:

$('#dataprocess').html(html);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论