fanboime Posted May 4, 2014 Share Posted May 4, 2014 Here is my button $( "#editVehicle" ).button().click(function( event ) { event.preventDefault(); var vp = $("input[name=vehicle_plate]").val(), dataString = 'vehicle_plate='+ vp; $.ajax({ type: "POST", url: "editvehicle.php", data: dataString, dataType: "json", success: function(data){ if(!data.error && data.success) { $("input[name=vehicle_model]").val(data.vehicleName); $("input[name=assigned_driver]").val(data.assignedDriver); } else { alert(data.errorMsg); } } }); }); And here is my PHP <?PHP include("db.classes.php"); $g = new DB(); $g->connection(); if($_POST) { $vehiclePlate = $g->clean($_POST["vehicle_plate"],1); $g->edit($vehiclePlate); } $g->close(); ?> and here is my db.classes public function edit($vehiclePlate) { $sql = "select vehicle_name, driver_id from vehicles where vehicle_plate='$vehiclePlate'"; $result = mysql_query($sql) or die(json_encode(array("error" => 0, "errorMsg" => "MySQL query failed."))); $row = mysql_fetch_array($result); if(mysql_num_rows($row)) { echo json_encode(array( "success" => 1, "vehicleName" => $row['vehicle_name'], "assignedDriver" => $row['driver_id'] )); } else { echo json_encode(array( "error" => 1, "errorMsg" => "No rows returned" )); } } There is an input field in my html where i input the vehicle plate then when the user clicks the button the program searches the database for the vehicle name and driver_id with the plate the user entered and returns the value to another inputfield named "vehicle_name" and "assigned_driver" but nothing is happening when the button is clicked not even the error alert message. Any idea on where am i going wrong here? Quote Link to comment Share on other sites More sharing options...
trq Posted May 4, 2014 Share Posted May 4, 2014 What does dev tools console have to say about your request? Quote Link to comment Share on other sites More sharing options...
fanboime Posted May 4, 2014 Author Share Posted May 4, 2014 What does dev tools console have to say about your request? nothing no errors Quote Link to comment Share on other sites More sharing options...
fastsol Posted May 4, 2014 Share Posted May 4, 2014 Try this dataString = {'vehicle_plate' : vp}; First thing to do otherwise is do a check on the receiving php page to see what POST vars are being sent through and do a print_r() of that. Assuming your ajax call is getting to the correct page the print_r() shoudl display in the console of html depending on where you ave that going. Quote Link to comment Share on other sites More sharing options...
trq Posted May 4, 2014 Share Posted May 4, 2014 nothing no errorsNothing? So the request is not being made? Have you looked in the network tab? The request / response? What does the response look like? First thing to do otherwise is do a check on the receiving php page to see what POST vars are being sent through and do a print_r() of that. Assuming your ajax call is getting to the correct page the print_r() shoudl display in the console of html depending on where you ave that going. print_r() really? Do you not have a php debugger? Quote Link to comment 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.