Frostbourn Frostbourn - 4 months ago 17
PHP Question

How to load an external php file during an “onclick” event?

I trying to load google map on tab click to shorten the page load. I don't receive any errors in console. Just empty div

<div class="gmap"></div>
, when this should look like this:
<div class="gmap"><iframe style="border: none;" width="350px" height="150px" src="http://maps.google.com/maps?myadress"></iframe></div>
. It seems that script isn't executed on click.

What am I doing wrong? I need to mention that I still learning.

This is how the map script works: JSFIDDLE



map.php

<?php
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__).'/../../../..' ));
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe = JFactory::getApplication('site');

jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mod_module');
$moduleParams = new JRegistry();
$moduleParams->loadString($module->params);
?>
<div class="gmap" data-address="" data-lang="auto" data-width="350px" data-height="150px" data-zoom="12" data-bubble="false" data-pin-size="1" data-output="iframe"></div>


jquery.google-maps.js

// entire script above
// autoload maps
jQuery(function($) { $('.gmap').googleMaps(); });





First try



jQuery(document).ready(function($) {
$(".tab").click(function() {
$.getScript(window.location.origin + "jquery.googlemap.js", function() {
$(".div-inner").load("map.php");
});
});
});





Second try



I also tried this way but without effect:

jQuery(document).ready(function($) {
$(".tab").click(function() {
$.getScript(window.location.origin + "/jquery.googlemap.js", function() {
$.ajax({
type: "GET",
cache: false,
url: '/map.php',
success: function(data) {
$('.div-inner').html(data);

}
});
});
});
});

Answer

You need to call $('.gmap').googleMaps();