ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Safecracker "Uncaught SyntaxError: Unexpected token ILLEGAL"

June 05, 2012 6:58pm

Subscribe [3]
  • #1 / Jun 05, 2012 6:58pm

    webfu

    6 posts

    I’m getting the following error from the generated safecracker js:

    Uncaught SyntaxError: Unexpected token ILLEGAL

    (or in Safari “SyntaxError: Invalid character ‘\u65533’”)

    // <![CDATA[
    $(document).ready(function() {
     if (typeof SafeCracker == "undefined" || ! SafeCracker) { var SafeCracker = {markItUpFields:Bud1% @};}
    });
    // ]]>

    Looking at the generated code, there are some unexpected characters inserted, ie. “Bud1% @”

    In the source, line #137 of safecracker_lib.php gives

    $this->EE->javascript->output('if (typeof SafeCracker == "undefined" || ! SafeCracker) { var SafeCracker = {markItUpFields:{}};}');

    But this is obviously not translating to the view.

    I’m using
    ExpressionEngine: 2.4.0 Build 20120123
    Safecracker: 2.1

    I’ve tried upgrading to 2.5 and had no luck there either.

    What causes this issue and how can I rectify it?

  • #2 / Jun 05, 2012 7:41pm

    OwanH

    87 posts

    Hi webfu,

    What are you specifying in your templates as the HTML charset in the <meta charset=... tag? I’m not aware of any bug in EE 2.4.0/2.5 or Safecracker that should be causing this issue. If you like you can create a temporary CP login for me to have a look at your install and the specific template with the exp:safecracker tag in it.

  • #3 / Jun 05, 2012 8:28pm

    webfu

    6 posts

    Hi Owan, thanks for your reply.

    As for the charset, it’s utf-8.

    As a side note, I’m using the stash plugin to pass the view contents into a layout, so my code looks like such:

    {preload_replace:channel="pages_misc"}
    {embed="_layouts/full"}
    
    {exp:channel:entries limit="1" channel="{channel}" status="not closed|draft" require_entry="yes" url_title="{segment_1}"  {global:param_disable_default} }
      {if no_results}{redirect="404"}{/if}
    
    
      {exp:stash:set name="title"}{exp:low_widont}{title}{/exp:low_widont}{/exp:stash:set}
      {exp:stash:set name="content"}{cf_page_content}{/exp:stash:set}
      
      {exp:stash:append name="content"}
      {exp:safecracker channel="store_finder_item" return="store-form-thank-you" logged_out_member_id="4" datepicker="no" class="form-stacked"}
       <!-- no content necessary to fail -->
      {/exp:safecracker}
      {/exp:stash:append}
    
    
    {/exp:channel:entries}

    However, if I try to side-step stash and just have the template contents as:

    {exp:safecracker channel="store_finder_item" return="store-form-thank-you" logged_out_member_id="4" datepicker="no" class="form-stacked"}
    <!-- no content necessary to fail -->
    {/exp:safecracker}

    It still fails.

    I afraid I cant presently issue a login as its running locally, though if we cant work it out by theory alone I may have to deploy it somewhere.

    Thanks, Vaughan.

     

  • #4 / Jun 05, 2012 10:24pm

    OwanH

    87 posts

    Hi Vaughan,

    Thanks for the info. Use of the stash module should have no bearing on this issue. From what you have said I really do not see how you could be getting such an error or why. I myself am using safecracker on a site running EE 2.4.0 and another that I upgraded to 2.5.1 this weekend and I am not experiencing any similar issue.

    What kind of setup do you have for your local environment? PHP version, php.ini memory limit setting, Apache or IIS, etc.?

  • #5 / Jun 05, 2012 10:37pm

    webfu

    6 posts

    Hi Owan. Yeah it is strange, here’s the setup, it’s all fairly standard and out of the box:

    ExpressionEngine 2.4.0 Build 20120123
    MSM not installed
    jQuery 1.7.1
    MySQL 5.1.37
    Server Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/1.0.1 DAV/2 PHP/5.3.10

  • #6 / Jun 05, 2012 11:05pm

    OwanH

    87 posts

    Hi Vaughan. Your environment is exactly the same as mine except that my server runs MySQL 5.1.62, other than that I’m running exact same Apache, PHP, mod_ssl and jQuery versions and like I said, some of my EE sites are still 2.4.0, only a couple I’ve upgraded to 2.5.1 so far. I’m all out of ideas. Can you deploy it online to see if the issue persists in a live environment?

  • #7 / Jun 06, 2012 3:25pm

    Dan Decker

    7338 posts

    Hi webfu,

    If you are including your own jQuery on the page, you need to be sure to see the include_jquery= parameter of SafeCracker:

    {exp:safecracker channel="store_finder_item" return="store-form-thank-you" logged_out_member_id="4" datepicker="no" class="form-stacked" include_jquery="no"}

    That will prevent SafeCracker from loading it’s version of jQuery, which I suspect is causing your conflict here.

    Cheers,

  • #8 / Jun 06, 2012 5:52pm

    webfu

    6 posts

    Hi Dan, thanks for your response.

    I’m afraid the jquery doesnt seem to be the issue, when I turn it off I still get the same error, with the addition of a new error:

    Uncaught TypeError: Cannot read property 'manager' of null

    For the resource:

    ?ACT=26&ui=core,widget,mouse,position,draggable,resizable,button,dialog&plugin=scrollable,scrollable.navigator,ee_filebrowser,ee_fileuploader,markitup,thickbox,toolbox.expose,overlay,tmpl&v=1330470780&use_live_url=y

    Also, if I disable javascript entirely, the malformed line in question (below) still appears in the page markup:

    if (typeof SafeCracker == "undefined" || ! SafeCracker) { var SafeCracker = {markItUpFields:Bud1% @};}});

    Suggesting that it’s not an issue with the JS on the page?

    Cheers, Vaughan.

  • #9 / Jun 06, 2012 6:13pm

    webfu

    6 posts

    To add some more info, I’ve just found that another pair of curly braces in my JS has been replaced with the nefarious “Bud1% @”. This time it’s in the Google Maps module, the function that prints out:

    var '.$map_id.'_window = {};

    ends up becoming

    var map_window = Bud1% @;

    when rendered.

    Something somewhere is replacing this for me, any idea what?

  • #10 / Jun 06, 2012 7:06pm

    webfu

    6 posts

    Ok I’m fairly certain I’ve found the problem here: SnippetSync

    It looks a lot like SnippetSync has picked up a .DS_Store file and turned it into a global variable with a blank name, and is replacing every instance of {} with the contents of the file for me.

    I’ve removed it and we’re back in business. Thanks a bunch for your help guys!

    Vaughan.

  • #11 / Jun 07, 2012 11:21am

    OwanH

    87 posts

    Hey Vaughan, glad to know you got it sorted. All the best with your development efforts!

  • #12 / Jun 12, 2012 10:23am

    Shane Eckert

    7174 posts

    Hey webfu,

    Glad to see that the community was able to help you out here. That’s awesome!

    If you need anything else, please just let us know by opening a new thread.

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases