0

i create one button in html

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

and use jquery onclick event and create iframe , i want to send lat, long and title to iframe and create dynamic map but i send get 10 % discount as a subtitle , i get following error

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>');
}

how can i send data to iframe . i dont want to use form and send data by post method.. without using form i can post data to iframe

hakre
  • 193,403
  • 52
  • 435
  • 836
rash111
  • 1,307
  • 4
  • 19
  • 35

2 Answers2

3

Pass them in the query string:

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>');

In codeigniter code you would retrieve them:

$lat = $this->input->get("ad_lat");
$lng = $this->input->get("ad_lng");
$subtitle = $this->input->get("ad_subtitle");
Esailija
  • 138,174
  • 23
  • 272
  • 326
  • public function frame_stimulator() { $data['lat']=$this->input->get("ad_lat"); $data['lon']=$this->input->get("ad_lng"); $data['address']=$$this->input->get("ad_subtitle"); } it gives 500 internal server error – rash111 Jul 27 '12 at 10:26
  • @rash111 why do you have `$$this->input->get`? Why 2 dollars? Try it with only one: `public function frame_stimulator() { $data['lat'] = $this->input->get("ad_lat"); $data['lon'] = $this->input->get("ad_lng"); $data['address'] = $this->input->get("ad_subtitle"); } ` – Esailija Jul 27 '12 at 10:27
  • sorry brother and thanks it is working, but i have another question when i change lat, long in input field and again click on simulate button it show previous lat , long map.. why this is happen – rash111 Jul 27 '12 at 10:33
  • public function frame_stimulator() { $data['lat']=$this->input->get("ad_lat"); $data['lon']=$this->input->get("ad_lng"); $data['address']=$this->input->get("ad_subtitle"); $this->load->view('frame_stimulator',$data); } here i accept data and pass to view – rash111 Jul 27 '12 at 10:40
  • – rash111 Jul 27 '12 at 10:42
  • @rash111 just the relevant javascript code only, you can delete those comments. The comments you just made, they are not relevant to the problem. – Esailija Jul 27 '12 at 10:43
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

Community
  • 1
  • 1
Snow Blind
  • 1,164
  • 7
  • 12