0

我在 html 中创建一个按钮

<input type="button"  value="Simulate" class="submit_btn"  id="stimulate" />

并使用 jquery onclick 事件并创建 iframe,我想将 lat、long 和 title 发送到 iframe 并创建动态地图,但我发送了10% 折扣作为字幕,我收到以下错误

GET http://domain name/name of controller/name of function/57.643821505750964/12.180534033203116//get%2010%%20discount 400 (Bad Request)



$("#stimulate").click(function() {
var ad_lng = document.getElementById("longclicked").value;
var ad_subtitle = document.getElementById("ad_subtitle").value;
var ad_lat = document.getElementById("latclicked").value;

$('#iframeHolder').html('<iframe id="iframe" src="<?php echo base_url(); ?>index.php/admin/frame_stimulator/'+ad_lat+'/'+ad_lng+'/'+ad_subtitle+'" width="700" height="550" scrolling="no"  frameborder="0"></iframe>');
}

如何将数据发送到 iframe。我不想使用表单并通过 post 方法发送数据.. 不使用表单我可以将数据发布到 iframe

4

2 回答 2

3

将它们传递到查询字符串中:

var ad_lng = encodeURIComponent( document.getElementById("longclicked").value );
var ad_subtitle = encodeURIComponent( document.getElementById("ad_subtitle").value );
var ad_lat = encodeURIComponent( document.getElementById("latclicked").value );

$('#iframeHolder').html('<iframe id="iframe" src="<?php echo base_url(); ?>index.php/admin/frame_stimulator?ad_lat='+ad_lat+'&ad_lng='+ad_lng+'&ad_subtitle='+ad_subtitle+'" width="700" height="550" scrolling="no"  frameborder="0"></iframe>');

在 codeigniter 代码中,您将检索它们:

$lat = $this->input->get("ad_lat");
$lng = $this->input->get("ad_lng");
$subtitle = $this->input->get("ad_subtitle");
于 2012-07-27T10:20:23.257 回答
1

You can invoke a javascript function in an iframe from the parent/container page. So if you script a function in the iframe page that takes data as a parameter, then you can invoke it from the main page that contains iframe.

Check this: Invoking JavaScript code in an iframe from the parent page

于 2012-07-27T10:27:02.477 回答