Welcome Guest, Not a member yet? Register   Sign In
Passing variable from Javascript to php
#1

[eluser]Alenazi[/eluser]
I am using a CI to build website that has Google map feature.Specifiably, after the user place a marker in the map, I want position of the marker,which is just a variable, to be saved in a PHP variable so I can insert it to the database.
What is the most efficient way to do it with CI.
#2

[eluser]bobbybaboon[/eluser]
Crazy, I did this same task today. In my case, I created a form with two hidden inputs, one for latitude and one for longitude. I attached an event to the DragEnd event of the marker that updates these inputs with the marker's new coordinates. Then when the user is done they hit submit and the new point is added to the database just like a normal form.

I know there is a tutorial somewhere on the internet with a sample application where you can place a point and it automatically updates the database. I'm not sure where it is, but if my form submit solution isn't practical for your situation I could try and dig it up for you.
#3

[eluser]Alenazi[/eluser]
Could you please post the portion of the code where you pass the variable from the JavaScript to php

thank you very much
#4

[eluser]obiron2[/eluser]
why not pass the lat and long as part of the URL using an ajax call.

www.mywebsite.com/googlemaps/updatepin/userid/pinid/lat/long

where
googlemaps is your controller
updatepin is your method

userid/pinid/lat/long are four variables to identify the user, the pin (if you are moving it) and the cursor locations. You can then insert/update the database as required and await the ajax response

if your lat an dlong contain invalid characters, you may neec to urlencode() them before you send them and then urlunencode() when you get to CI.

Obiron
#5

[eluser]bobbybaboon[/eluser]
Here's the tutorial I used. It's not codeigniter specific but the concepts are easy enough:
http://code.google.com/support/bin/answe...opic=11364


You could also do something like Obiron mentioned as well.




Theme © iAndrew 2016 - Forum software by © MyBB