• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JS nightmares

Ok. I have tried for the past several days to help myself and have come up short. Now I understand why I rather stay with PHP ... Finally I am down to one last piece of the puzzle to complete this app:

I have some data in an array (Google Maps Lat / Lng ) that I need to get back into my CI php files to query my database. Yes, I know I could just query directly via PHP but would rather stay with the CI Framework.

If I simulate the process by creating two pages; one for the map the other for the php app I can pass the data with the GET command just fine. When I try to pass via the GET from the JS to the CI page the $_GET ends up empty.

I tried figuring out how to perform this with POST instead but ended up wasting another day of my life trying this and that to no avail.

Could someone be kind enough to offer me some wisdom here?

Thank you greatly!

check google maps example with CI in my signature may be help you. it is using jquery javascript framework


Thank you. Unfortunately I am not wanting to require the user to click a button. I obviously missed a crucial part of the problem.

I have an application that the user visits the page. Enters 3 key pieces of information to cause the scripts to create boundary boxes along their route: http://www.shiprightnow.com/custom/demo/routeBoxer.php

My issue is once they have clicked submit I want to capture the array displayed below the map and get into my CI app. I have this array being handled at present in php but not integrated into CI.

Does this help clear the mudded waters?


Get is not working in CI, you have to post your data, if you are using any ajax try to post your data will help you, try to use jquery to do this dont use raw javascript really easy with jquery check here jquery ajax doc


here is doc for jquery post


get data in CI and do it normal way as you did example you send me


Thank you for the information.

Would you mind pointing me in a direction to understand the following?

Using Firebug I can see that AJAX has Posted the data to the CI controller. The controller has responded with a $data array. I see both the Post and Response in Firebug.

What I am stuck with is getting this data to display on the screen.

on the page I have:
<div id="result"></div>

in the [removed]
type : "POST",
url : "site url to controller/function",
data : "&coords;=" + boxes,
dataType: "json",
success: function(data){$("#result").html(data);}

What am I not understanding?

Thank you!

are you returning any output back from CI to your page if yes there should be no problem you have to echo it or just call a view, really good you are using firebug good for debugging ajax and monitor request response of data


Thank you. Yes. First I call the controller and POST a to, from and distance fields to the controller which passes them on as it calls a view. In the view the Google Maps JS App runs and uses the to, from and distance to call the routeBoxer, distance and directionService APIs. Once the APIs have run I capture the coordinates of the routeBoxer result and pass them back to the CI Controller:
    type : "POST",
    url : "http://www.shiprightnow.com/custom/map/search",
    data : "&coords;=" + boxes,
    dataType: "json",
    success:  function(data){$("#result").html(data);}
Post Data:
coords    ((34.210144882666555, -111.80111777590123), (34.67328658844438, -102.11798)),((34.67328658844438, -112.3707141156601), (35.136428294222185, -96.42201660241108)),((35.136428294222185, -112.3707141156601), (35.59957, -95.28282392289329)),((35.59957, -112.3707141156601), (36.06271170577782, -107.24434705783005)),((35.59957, -104.96596169879449), (36.06271170577782, -91.8652458843399)),((36.06271170577782, -98.70040196144664), (36.52585341155563, -91.8652458843399)),((36.52585341155563, -96.99161294216995), (36.98899511733345, -91.8652458843399))

Once the CI Controller/Function has parsed the Coordinates it is passing them back to the page (currently just for view, will be several other objects of data after I get past this hurdle):
CI function:
$data['coords'] = (parseCoords($_POST['coords']));
    echo 'uri is<br />';
    print_r($this->uri->uri_string()); echo '<p>';
    print_r($_POST); print_r($_GET);
    echo '<p />thats it';
At this point I can see the result of the above in the header via FireBug. However, this data never makes it to the display:
capture Result from Firebug:
<table><tr><td></td></tr></table>uri is<br />/map/search<p>Array
    [coords] => ((34.210144882666555, -111.80111777590123), (34.67328658844438, -102.11798)),((34.67328658844438, -112.3707141156601), (35.136428294222185, -96.42201660241108)),((35.136428294222185, -112.3707141156601), (35.59957, -95.28282392289329)),((35.59957, -112.3707141156601), (36.06271170577782, -107.24434705783005)),((35.59957, -104.96596169879449), (36.06271170577782, -91.8652458843399)),((36.06271170577782, -98.70040196144664), (36.52585341155563, -91.8652458843399)),((36.52585341155563, -96.99161294216995), (36.98899511733345, -91.8652458843399))
<p />thats it

Am I not pointing JS to the proper div id? I have no idea as to what the problem is at this point...

I think part of the problem is you are telling jQuery that the result is going to be in json format ( dataType: "json"), and then you pass it html + json (according to your FB output). Also, that is not json, its a php array. You need to run json_encode() on the array before sending it back from the /custom/map/search function.

@umefarooq and @CroNiX


CroNiX you were right the data type was holding up that final piece it needed to be html as I am wanting to display html data.

umefarooq thank you for your help in leading me in the direction of ajax and the examples


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.