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?
 
Michel PlungjanConnect With a Mentor IT 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
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Michel PlungjanIT ExpertCommented:
Trailing comma makes IE unhappy

Either add a dummy object to the end or remove the comma
0
 
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
 
pigmentartsAuthor Commented:
thanks will have a play
0
All Courses

From novice to tech pro — start learning today.