slandau
slandau

Reputation: 24052

Getting Javascript regular expression error -- not even using them

function GenerateTermSheet()
        {
            var urlString = <%= System.Web.VirtualPathUtility.ToAbsolute("~/mvc/Indications.cfc/CreateTermSheet/")%>
            var guidString = GetGUIDValue();
            alert(urlString);
//            $.ajax({
//                    type: "POST",
//                    url: urlString,
//                    success: function(data) {
//                        alert('Success!');
//                    }
//                });
        }

When I use firebug...I can see that it applies the correct path to urlString, however it returns this error at that line?

invalid regular expression flag v
[Break On This Error] var urlString = /Extranet/mvc/Indications.cfc/CreateTermSheet/ 

What could this be?

Upvotes: 0

Views: 503

Answers (1)

Felix Kling
Felix Kling

Reputation: 816364

You have to enclose the inserted text with quotations marks:

var urlString = '<%= System.Web.VirtualPathUtility.ToAbsolute("~/mvc/Indications.cfc/CreateTermSheet/")%>';

Otherwise the text is interpreted as JavaScript and one way of defining regular expressions is with /.../. So /Extranet/ is recognized as regular expression and everything after that is treated as modifiers (or flags) . m is a valid modifier, but v isn't and there it errors.

Upvotes: 3

Related Questions