Reputation: 23
I Use a json onclick script for triggering a php function. I call the php function with:
$('#dtable').on('click', '[name=option3]', function () {
var select = $(this);
var id = select.attr('id');
$.post('index.php/stop/'+id+'', function(json) {
if (json && json.status) {
$("#failure").show().delay(2500).fadeOut(1500);
} else {
$("#success").show().delay(2500).fadeOut(1500);
}
}
);
} );
If the item is trigger he calls a slim property in my index.php
$admin->slim->post('/stop/:action', function($action) use ($admin) {
$admin->slim->contentType('application/json');
echo json_encode($admin->cont->Stop($action));
After this he triggert the function
function Stop($action) {
$port = $action;
$connection = @fsockopen($this->cfg->base_host, $port, $errno, $errstr, 1);
if (!$connection) {
return false;
} else {
$pid = $this->db->query("SELECT pid FROM testdb WHERE port='" . $port . "'", SQL_ALL, SQL_ASSOC);
if ($pid == "") {
return false;
} else {
......
}
}
}
}
}
the only thing is that the answer from json is always success but there is no return from true or false from the function
Does someone knows what i doing wrong or can someone give me some advice.
Upvotes: 0
Views: 85
Reputation: 142631
Use alert(json);
before if (json && json.status)
to see what you get. I'm sure json
is not what you expect. It seems json == false
(because function Stop()
return false
) and there is no json.status
- or maybe rest of your Stop
function return something more.
Upvotes: 1