I call my API with following Code (as well for other Websites):
$(function () {
$("#hb_api").load("http://api.site.de?apikey=71290473059");
$("#hb_api").load("http://api.site.de/src/controller.js");
})
controller.js contains following Code:
$(function () {
$('#btn1').on('click', function () {
var vars = {
test: $('#test').val(),
action: 'POST'
}
$.ajax({
url: "http://api.site.de/src/api_controller",
data: vars,
type: "POST",
dataType: "json"
}).done(function (d) {
var outp = d.response.post;
var outs = d.response.status;
$('#outp').html(outp + ", " + outs);
}).fail(function (xhr, textstatus) {
console.log(xhr);
console.log(textstatus);
})
})
})
And the index site this:
$api_key = $_GET['apikey'];
if (!isset($api_key)) {
header('HTTP/1.0 404 Not Found', true, 404);
exit();
}
require 'src/database.php';
$stmt_api = $pdo->query("SELECT `api_key` FROM `api` WHERE api_key = '{$api_key}'");
$q_api_key = $stmt_api->fetch();
if (!$q_api_key >= 1) {
header('HTTP/1.0 404 Not Found', true, 404);
exit();
}
<input type="text" id="test" value="test">
<div class='btn' id="btn1">Senden</div>
I can bind in the HTML Structure, but when i click the button, nothing happens. No Network activity or error code.
Is there a restriction, if i click the button? So how can the button call the AJAX Event, when it's clicked?