more errors in IE jquerysqlbuilder-0.06.js

Having more errors with the following file in IE only. I get the following set of errors


User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; MS-RTC LM 8; OfficeLiveConnector.1.4; OfficeLivePatch.1.3; AskTB5.5)
Timestamp: Thu, 1 Apr 2010 15:34:41 UTC


Message: Expected identifier, string or number
Line: 106
Char: 13
Code: 0



jquerysqlbuilder-0.06.js
LVL 12
pigmentartsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
can you
alert(jsonstr)    
            var j=eval('(' + jsonstr + ')');    

please on line 105

0
pigmentartsAuthor Commented:
thanks :)
alert box is shown in the image

screendump.png
0
Michel PlungjanIT ExpertCommented:
Trailing comma makes IE unhappy

Either add a dummy object to the end or remove the comma
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

pigmentartsAuthor Commented:
thanks for taking the time to look at this
from which part, line?
0
pigmentartsAuthor Commented:
dummy object, could you give me an example, thanks
0
Michel PlungjanIT ExpertCommented:
You JSON has a traling comma
Either remove it or add a {}, "" or [] to the end before the last } after wheredata[],
0
Michel PlungjanIT ExpertCommented:
e.g.

wheredata[]}
or
wheredata[],""}

If you cannot, then change
 
            var j=eval('(' + jsonstr + ')');  

to

jsonstr = jsonstr.substring(0,jsonstr.length-2)+"}";
            var j=eval('(' + jsonstr + ')');  

0
pigmentartsAuthor Commented:
like this...

                         data=data+'wheredata:[';
                            $('span.sqlwhere').each(function(){
                              var col_slot=$(this).find('a.addnewsqlwhere').attr('href').substr(1);
                              var op_slot=$(this).find('a.addnewsqlwhereoperator').attr('href').substr(1);
                              var chain_slot=$(this).find('a.addnewsqlwherechain').attr('href').substr(1);
                              var col_value=$(this).find('span.addnewsqlwherevalue').html();

                             
                              var columndata= '{'+
                                  'columnslot:'+col_slot+','+
                                  'opslot:'+op_slot+','+
                                  'chainslot:'+chain_slot+','+
                                  'columnvalue:"'+col_value+'",'+                                  
                                '},';
                              data=data+columndata;            
                            });        
                          data=data+'][],';//close where data  
0
pigmentartsAuthor Commented:
changing


            var j=eval('(' + jsonstr + ')');  

to

jsonstr = jsonstr.substring(0,jsonstr.length-2)+"}";
           var j=eval('(' + jsonstr + ')');  

stops it working in firefox tho
0
Michel PlungjanIT ExpertCommented:

    data=data+'][], <<<<<<<< still a trailing comma

Give me a sec
0
Michel PlungjanIT ExpertCommented:
This works for me

<script>
var jsonstr = '{ reportid:9000, columndata: [{columnslot:19,columnas:"Advanced Credits"},],sortdata:[],groupdata:[],wheredata:[],}'
alert(jsonstr.substring(jsonstr.length-2))
if (jsonstr.lastIndexOf(',}')==jsonstr.length-2)
  jsonstr = jsonstr.substring(0,jsonstr.length-2)+"}";
alert(jsonstr)
var j=eval('(' + jsonstr + ')');  
</script>

Open in new window

0
Michel PlungjanIT ExpertCommented:
oops
missing stuff
0
Michel PlungjanIT ExpertCommented:
you have one more after

columnas:"Advanced Credits"}, <<<<<
0
Michel PlungjanIT ExpertCommented:
You could rewrite your functions to have the comma FIRST

I do this in JS

var str="";
for (....) {
  str+=","+someValue;
}
if (str) str=str.substring(1);// remove leading comma

alternative for you is

var str ="";
var first = true;
for (...) {
  if (first) first=false;
  else str +=",";
  str += someVar;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pigmentartsAuthor Commented:
thanks will have a play
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.