0

My task is to get the html data from an ajax call and upon success i want bind to a specific tag and remove the rest of html data.

"Specific div tag here in this case is #divtest

i wanted to remove are divtbldataresults ,divend

data is html "

THE ISSUE IS IT IS THROWING JAVASCRIPT ERROR, I WAS WONDERING DOES MY CODE HAVE SYNTAXT ISSUES OR AM I DOING SOMETHING WRONG .THANKS IN ADVANCE

$.ajax({
   type: "POST",
   cache: false,
   url: '@Url.Content("~/SyndromicQuery/QueryPeriod")',
   data: { selectedItem: selectedItem,
   startdate: startdate,
   enddate: enddate,
   queryid: queryid
},
success: function (data) {
   var jqObj = $(data);
   jqObj.find('divtbldataresults').remove();
   jqObj.find('divend').remove();
   $('canvas').remove();
   $("#divtest").empty().append(jqObj);

}

5
  • You did close it right? }); Jul 31, 2013 at 17:19
  • I think you are missing the class (.) or the id (#) marker in the selector. Also, if this divs are a first level childs you need to use .filter() instead of .find() Jul 31, 2013 at 17:20
  • Have you closed the brackets for the success function and ajax() in your full code or are they really missing?
    – Mike Brant
    Jul 31, 2013 at 17:21
  • Microsoft JScript runtime error: Syntax error, unrecognized expression: <html> <head> <script src="/Scripts/jquery-ui.js"></script> <link rel="stylesheet" href="/Scripts/theme/jquery.ui.all.css" /> <script type="text/javascript" src="/Scripts/Chart.js"></script> </head> Jul 31, 2013 at 18:04
  • The above error is happening when i use var jqObj = $(data); Jul 31, 2013 at 18:05

2 Answers 2

0

This could be because #divtest is a child of one of the page elements you are removing.

1
  • The error is coming once i put the html data into jquery object. var jqObj = $(data) Aug 1, 2013 at 14:46
0

Seems that you're looking for: <divtbldataresults> or <divend> wich I hope you are not using!

If they are classes, try:

var jqObj = $(data);
   jqObj.find('.divtbldataresults').remove();
   jqObj.find('.divend').remove();

If they are id's, try:

var jqObj = $(data);
       jqObj.find('#divtbldataresults').remove();
       jqObj.find('#divend').remove();

Also, if they're first level (or direct) childs. try:

var jqObj = $(data);
       jqObj.filter('.divtbldataresults').remove();
       jqObj.filter('.divend').remove();
4
  • I have tried evrything still the error throws the error come when i use this statement var jqObj = $(data) Aug 1, 2013 at 14:38
  • maybe you should post what data returns (before that) just console.log(data) and paste it here Aug 1, 2013 at 16:50
  • 1
    Toni it is working fine now as i converted html to var jqObj = $.parseHTML(data) Aug 1, 2013 at 17:26
  • I am glad you solved the problem. but there is no way your original code worked, right? you needed to add the class/id identifier, no? Aug 1, 2013 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.