3

I am facing issue in my code. It gives a javascript error in IE8,

"SCRIPT1028: Expected identifier, string or number"  

My code,

<cfoutput>
<cfif iPro eq "M">
<cfset iIdLock = #DecryptX(iId)#>`

<script>
window.onbeforeunload = function(){
    var hook = true;
    if(hook){
        var r="#iIdLock#";
       $.ajax({                     
           type:'POST',
           async:false,
           url:"setlock.cfm",
           data:"s="+r,
           success: function(){},
           error: function(){},
        });
    }
}
</script>

</cfif>
</cfoutput>

What could be the issue?

Amar
  • 13,202
  • 7
  • 53
  • 71
Rikhi Sahu
  • 655
  • 1
  • 7
  • 19
  • 2
    Two suggestions. You don't need those # # in your , see [this article](http://cfmlblog.adamcameron.me/2013/09/when-to-use-pound-signs.html). And it's always a good idea to run your JS through a validator like [JSLint](http://www.jslint.com/) which would pick up the issue with the trailing comma that Leigh correctly identified – duncan Sep 17 '13 at 08:45

2 Answers2

5

Always a good idea to do a quick search on the error before posting :) A very quick search turned up this SO thread: SCRIPT1028: Expected identifier, string or number. One of the suggested causes is extra trailing commas. Looks like you have an extra comma after the "error" function:

    $.ajax({                     
           ...
           error: function(){},    
    });

That seems a likely cause, and at the very least it would cause some syntax error.

Community
  • 1
  • 1
Leigh
  • 28,765
  • 10
  • 55
  • 103
1

Actually I had used double quotes within Ajax and that is what caused my issue. I just replaced the double quotes with single quotes and everything is working fine now.

var r="#iIdLock#"; -> var r='#iIdLock#

url:"setlock.cfm", -> url:'setlock.cfm',

data:"s="+r, -> data:'s='+r,
Community
  • 1
  • 1
Rikhi Sahu
  • 655
  • 1
  • 7
  • 19