I am making a plugin that creates a tab with a link that exectutes a php file using AJAX. However, it will not execute the php file when clicking on the link. I have tried for 20 hours to get it working but somehow it just wont execute. Is cb blocking ajax in tabs? Am I missing something? Im soon going crazy.
Code:
$return .= '<script>function performAjaxSubmission() {
$.ajax({
url: \''.JURI::base().'path/to/file/file.php\',
method: \'POST\',
data: {
action: \'save\',
field: $("#db_field").val(),
val: $("#db_value").attr()
},
dataType:\'json\',
success: function(data) {
alert(data.success);
}
});
return false;
}
jQuery(document).ready(function() {
$(".savebtn").click(performAjaxSubmission);
});</script>';
$return .= '<a href="#" class="savebtn" db_field="1" db_value="80">Click here</a>';
I put the javascript like that to see that the path to the php file was correct.
Code:
<?php
$dbhost = 'localhost';
$dbuser = '*';
$dbpass = '*';
$dbname = '*';
$message = '';
try {
$db = new PDO('mysql:dbname='.$dbname.';host='.$dbhost.';charset=utf8', ''.$dbuser.'', ''.$dbpass.'');
} catch (PDOException $ex) {
echo 'Connection failed: ' . $ex->getMessage();
}
$userid = $_POST['db_field'];
$level = $_POST['db_value'];
$db->query('UPDATE `dbname` SET test="1" WHERE id="80"');
$message ="Updated Sucessfuly!";
echo json_encode(array('success'=>$message));
?>
The query is also just a placeholder to see that its working, it is executing when I open the php file manually. I really need to get this working.
Thanks in advance,
LnG