friedice Posted September 11, 2010 Share Posted September 11, 2010 hello, i got my gmaps working couple months ago using PEAR templates and php with js however i was thinking of changing it using ajax to make it more beta right now: searchdoctor.php -> forms for users to select criteria, posts all that data into resultdoctor.php and then calls a query into the database to search and return a map using js with displaymap.php wat im lookin after for and tryin to do is to instead of redirecting the page , it can use ajax to load the result page into the search one under the forms or something.. is this possible? thx Quote Link to comment https://forums.phpfreaks.com/topic/213136-gmap-help-with-ajax/ Share on other sites More sharing options...
friedice Posted September 13, 2010 Author Share Posted September 13, 2010 anyhelp pls? i can also upload the code as well if u need? thx Quote Link to comment https://forums.phpfreaks.com/topic/213136-gmap-help-with-ajax/#findComment-1110523 Share on other sites More sharing options...
gamesmstr Posted September 14, 2010 Share Posted September 14, 2010 Yes, it is very possible and not difficult. Create a DIV under your form that is blank and has an ID. Then use an ajax call to load displaymap into the target DIV. I assume you will have to pass your form data through the ajax call. That is also not difficult. Assume your div is set up like this: <div id="mapbox"></div> And your form has 2 fields and a submit: <input type="text" id="street"> <input type="text" id="city"> <input type="button" value="Submit" onclick="javascript:showmap();"> In the <HEAD> section of your page, you'll need something like this: <SCRIPT> //Define AJAX call function createXMLHttpRequest() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } return false; } //Define function to call your php file and send it to it's target function showmap() { var xmlHttp_out = createXMLHttpRequest(); var street= document.getElementById("street").value; var city= document.getElementById("city").value; params = "street=" + street+ "&city=" + city; xmlHttp_out.open("POST","displaymap.php", true); xmlHttp_out.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp_out.onreadystatechange = function() { if(xmlHttp_out.readyState == 4 && xmlHttp_out.status == 200) { document.getElementById("mapbox").innerHTML = xmlHttp_out.responseText; } } xmlHttp_out.send(params); } </SCRIPT> On pressing the submit button, it calls the Javascript function showmap(). The function reads the contents of your fields and passes them via the POST method to displaymap.php and displays the results in the "mapbox" div. Every time the submit button is pushed it will repeat with whatever new data is in the fields. Quote Link to comment https://forums.phpfreaks.com/topic/213136-gmap-help-with-ajax/#findComment-1110821 Share on other sites More sharing options...
friedice Posted September 14, 2010 Author Share Posted September 14, 2010 ahk cool thx for that tip but i have several displaymap.php like 3 and all do abit different things on the map in those displaymap.php, all that is inside are all js code deguised in php to hide the js from the user, so everything that the search page posts all go to the result page which makes the query to the database to display the details and then calls the js map in display map.. could i just call xmlHttp_out.open("POST","result.php", true); this page from the search and then calls the map one? Quote Link to comment https://forums.phpfreaks.com/topic/213136-gmap-help-with-ajax/#findComment-1110879 Share on other sites More sharing options...
gamesmstr Posted September 16, 2010 Share Posted September 16, 2010 I'm not sure I follow what you are trying to do there. If you are trying to open a php file within a php file from an ajax call, I'm not sure that will work. Remember that xmlHttp_out is simply a variable assigned to a return from the function that creates the XML request. What you CAN do is include the 1st file as a function that return the data for the 2nd file and call that via ajax. Quote Link to comment https://forums.phpfreaks.com/topic/213136-gmap-help-with-ajax/#findComment-1111530 Share on other sites More sharing options...
friedice Posted September 19, 2010 Author Share Posted September 19, 2010 dw ive decided not to use ajax but just to post it on the same page instead so thx anyways, still have one trouble with it tho lol Quote Link to comment https://forums.phpfreaks.com/topic/213136-gmap-help-with-ajax/#findComment-1112748 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.