php - Using javascript variable in mysql query and populate listview -
I have a Google Map / Marker app where I want to use the marker id in a mysql query to extract data When the marker is clicked on the marker related to the marker.
Variables are assigned when the marker is clicked and I am using AJAX to transfer the value to a php file for the variable. Mysql query
JS On the success, I've called the Guesthocker function, which populates the list view with database values. PHP No error when I run the application, but the list view is empty. < P> When I delete the Ajax code and W here, the code of section from SQL here gives all the values in that table, so I know that it works about listing the DB connection and output. Should be wrong with the variables passing in Ax or if I am calling the code incorrectly. Any advice is highly appreciated, for some reason you are requesting a separate agax request for success The data will be already passed to the success function, so simply remove the second ajax request: Also, as @ Paul Rauf has stated, your post data key does not match with your PHP, either Change the data in your AJAX to: or change your php Use the key
function bindInfoWindow (marker, map, infoWindow, html) {google.maps.event.addListener (marker, 'click' , Function () {infoWindow.setContent (html); infoWindow.open (map, marker); var site_id = marker.get ("id"); $ .ajax ({url: 'getoffer.php', type: "post ", Data: {site: site_id}, success: recipient});}); }
var output1 = ''; Function getoffers ($ {. .post ("getoffer.php? Getjson", function (data) {var data = JSON.parse (data); console.log (data); $ .each (data, function (index, value) ) {Output1 + = '& lt; li Data-id =' + value.offer_id + '& gt; & lt; a href = "#" "& gt;' + value.offer_title + '& lt; / a & $ ('# OfferList') .HTML (Output 1) .listview (). Listview ('Refresh');})}} / Pre>
& lt ;? php $ site = $ _POST ['site_id']; requirement ("dbconnect.php"); { $ DBH = New PDO ("mysql: host = try $ server; dbname = $ database; charset = utf8", $ username, $ password, array (PDO :: MYSQL_ATTR_INIT_COMMAND = & gt; "SE T NAMES 'utf8' "))}} Hold (PDOException $ e) {Print" Error! ". $ E-> Message received ()." & Lt; Br / & gt; "; Die ();} $ STH = $ DBH-> Create (select where site_id = '$ site'"); $ STH-> Execution (); $ arr = $ STH- & Gt; fetch all (); echo json_encode ($ arr); die ();
function recipient (data) {// $. Post ("getoffer.php? Gjjjson", function (data) {var data = JSON.parse (data); Console.log (data); $ .eee (data, function (index, value) {output1 + = '& lt; Li data-id = '+ value $ (' #listlist '). Html (output 1); $ 1 ($ 1) .listview () Listview ('Refresh');}}}}
Data: {site_id: site_id},
site :
$ site = $ _POST ['site'];
Comments
Post a Comment