Last active
August 29, 2015 14:07
-
-
Save chukShirley/aee263e612c695df07ef to your computer and use it in GitHub Desktop.
AJAX delete supplier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<!-- Can be any kind of input as long as id is "supplierId" --> | |
<input type="hidden" id="supplierId"> | |
<button class="btn btn-default" id="supplier_deleteButton">Delete Supplier</button> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#supplier_deleteButton').on('click',function(){ | |
if (confirm('Are you sure you want to delete this supplier?')) | |
{ | |
$(this).button('loading'); | |
// Get supplier ID | |
var supplierId = $('#supplierId').val(); | |
// Call server side script and handle response | |
deleteSupplier().done(function(response){ | |
if (response.success == true) | |
{ | |
// Show success message | |
} else { | |
// Show error | |
$('#errorMessage').removeClass('hidden'); | |
// change state of error field to | |
} | |
}).always(function(){ | |
// Reset delete button | |
$('#supplier_deleteButton').button('reset'); | |
}); | |
} | |
}); | |
function deleteSupplier(supplierId){ | |
return $.ajax({ | |
url:'route/to/controller/action', | |
dataType:'json', | |
type:'POST', | |
data:{ | |
id:supplierId | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$peddlerId = $_POST['peddlerId']; | |
$user = $_SESSION['user']; | |
$db = Db::getInstance(); // Or wherever you get your db handler from | |
// Connect to the database | |
try{ $ToolkitServiceObj = ToolkitService::getInstance($db, $namingMode); } | |
catch (Exception $e) { | |
echo $e->getMessage(), "\n"; | |
exit(); | |
} | |
$ToolkitServiceObj->setToolkitServiceParams(array('InternalKey'=>"/tmp/$user", | |
'debug'=>true, | |
'plug' => "iPLUG32K")); | |
// Add parameter | |
$param[] = $ToolkitServiceObj->AddParameterChar('both', 1, 'peddlerId', 'peddlerId', $peddlerId); | |
// Call program | |
$result = $ToolkitServiceObj->PgmCall("[CL Program]", "[Library Name]", $param, null, null); | |
if($result['status'] == 0){ | |
$response['success'] = true; | |
} elseif ($result['status'] == 1) { | |
$response['success'] = false; | |
$response['error_field'] = $result['field']; | |
} else { | |
$response['success'] = false; | |
} | |
echo (json_encode($response)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment