如何在“onclick”事件期间加载外部php文件
How to load an external php file during an “onclick” event?
我试图在选项卡上加载谷歌地图以缩短页面加载。我在控制台中没有收到任何错误。只是空的div <div class="gmap"></div>
,而它应该是这样的:<div class="gmap"><iframe style="border: none;" width="350px" height="150px" src="http://maps.google.com/maps?myadress"></iframe></div>
。脚本似乎不是在点击时执行的。
我做错了什么?我需要提一下,我还在学习。
这就是映射脚本的工作方式: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(); });
第一次尝试
jQuery(document).ready(function($) {
$(".tab").click(function() {
$.getScript(window.location.origin + "jquery.googlemap.js", function() {
$(".div-inner").load("map.php");
});
});
});
第二次尝试
我也尝试过这种方式,但没有效果:
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);
}
});
});
});
});
我找到了一个解决方案。谢谢
jQuery(document).ready(function($) {
$(".tab").one('click', function() {
$(".div-inner").append('<div class="gmap" data-address="New York"></div>');
$.getScript(window.location.origin + '/jquery.googlemap.js', function() {
$('.gmap').googleMaps();
});
});
相关文章:
- 使用javascript在Flash中加载外部图像
- 如何在运行时在angular 2中加载外部js脚本
- Chrome扩展无法通过清单加载外部javascript
- 加载Angular视图后加载外部脚本
- Cordova/Phonegap在主要的Cordova网络视图中加载外部站点
- IE 9 BHO插件.加载外部JS文件时出现错误SCRIPT1014
- 是否有用于加载外部脚本的JavaScript库
- 使用纯Javascript加载外部URL内容
- 在Chrome扩展中加载外部javascript
- 在扩展 jQuery 之前加载外部资源
- 无法加载外部 JavaScript 文件 - Codeigniter
- jquery .load() 不加载外部 JS
- GO - html 文件无法加载外部 js 文件
- jQuery 不会使用 .load() 加载外部 html 模板
- 使用HTML5缓存时无法加载外部资源
- 色盒延迟打开;锁定“;当加载外部javascript文件时
- 使用load()加载外部文件,然后使用fancybox插件进行修改并显示
- 在Ember应用程序中加载外部域脚本
- html javascript加载外部脚本
- 如何防止加载外部资源,同时防止“在'文档'上执行'写入'失败”错误