I am having a problem with the jQuery Ajax function not sending the data to the corresponding php file, and then not running the success function. Here is my js:
function meetMember(empl_id) {
var member = {id: empl_id}
$.ajax({
type: 'POST',
url: 'php/infocheck.php',
data: member,
dataType: 'json',
success: function(data) {
alert('hi');
console.log(data);
$('#member-info').append(data);
}
});
}
And the infocheck.php code:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
include('db-info.php');
$id = $_POST['id'];
$q = "SELECT * FROM team WHERE empl_id = $id LIMIT 1";
$member = mysql_fetch_assoc(mysql_query($q));
$met = $member['ifmet'];
if($met != 1) {
mysql_query("UPDATE team SET ifmet = 1 WHERE empl_id = $id");
}
echo "<img src=\"game/images/{$member['image']}\" alt='' style='padding:2px 10px 0px 0px; float:left;' />";
echo "<h3>{$member['name']}</h3>";
echo "<h4><em>{$member['title']}</em><h4>";
echo "<p>{$member['description']}</p>";
?>
When I view the php file in the browser, I get the errors:
“Notice: Undefined index: id in /Applications/MAMP/htdocs/Development/ETL24/php/infocheck.php on line 8
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/Development/ETL24/php/infocheck.php on line 12″
The console.log and alert in the success function do not run. I do not even get the echo in the console when I view the php file. Please let me know of any ideas or questions you might have. Thank you.
Use
dataType: 'html'your file returnHTMLWhen your open the file on browser(
GET) yes you get a Error because it need to pass theidbyPOST.if you want to debug it change to
type: GETand on the url append?id=1