Javascript error – var missing

This topic contains 3 replies, has 2 voices, and was last updated by  Vikas 10 years ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #1431

    Avincom SAS
    Expired Member
    Post count: 2

    Hi,

    I have installed GD and all its add-ons except the event add-on.

    I have installed dummy data via the GD back-end procedure.

    I have a problem with the category listing page.

    When the page loads, the console shows the following error:
    Uncaught ReferenceError: geodir_map_v3_listing_map_1_jason_args is not defined

    I have looked at the GD demo site (url: http://wpgeo.directory/attractions/landmarks) and I can see in the source code a CDATA section with 2 defined vars : geodir_map_v3_listing_map_1 and geodir_map_v3_listing_map_1_jason_args.

    On my test website, I also have a similar CDATA section but only the first variable (geodir_map_v3_listing_map_1) appears alongside its definition.

    Of course, from then on, all subsequent Pinpoint attempts fail:
    Uncaught TypeError: Cannot read property ‘setAnimation’ of undefined

    Any idea where I could look to understand what is going on?

    Thank you.

    #1432

    Vikas
    Full Member
    Post count: 1128

    Hi,

    Plz let me know ur site url and wp-admin.

    Thanks

    #1852

    Avincom SAS
    Expired Member
    Post count: 2

    OK, I finally figured what was happening.

    The call to wp_localize_script in geodirectory/geodirectory-functions/map-functions/map_functions.php would fail and I think it is because I had more than one map displayed on any page.

    The line where it would fail i.e. where it would not correctly output the CDATA javascript line in the source code is : wp_localize_script( ‘geodir-map-widget’, $canvas_jason_args, $map_canvas_jason_args);

    Initially I thought the wp_enqueue_script was not performed at the right time. But I added a second enqueue_script just before the wp_localize_script and that did not fix the problem.

    Then I bumped into the following thread http://wordpress.stackexchange.com/questions/135821/creating-multiple-wp-localize-script-for-shortcode and got the idea to change the name of the handle.

    I think the reason for the error is that the same handle might be used more than once.

    So the way I fixed it is (for every wp_localise_script occurrence) by :
    – creating a unique handle
    – enqueueing the map.js script a second time using the unique handle
    – wp_localize_script using the unique handle.

    I know that map.js is now enqueued twice but I am trying to stick to the original code so I can easily upgrade my site.

    Cheers.

    #1890

    Vikas
    Full Member
    Post count: 1128

    OK great. It will be helpful to others too.
    Thanks

Viewing 4 posts - 1 through 4 (of 4 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket