It was working perfectly but for some time i have stopped working on this project. I am sending a delete request to my server and it gives me this Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://abc.dev/users/users/18. (Reason: CORS preflight channel did not succeed).(unknown)
The API is written in Yii framework. I am using CORS
extension for firefox , my GET, POST
method working perfectly fine but my DELETE
method seems like stuck.
My controller
$scope.delete = function (id)
{
if (confirm("Are you sure you want to delete the user") === true) {
$http({
method: 'DELETE',
url: 'http://abc.dev/users/users/' + id,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.success(function (data) {
$scope.singleuser = data;
console.log("function single user is processed");
$scope.user(); //call the function to reload
})
.error(function (data) {
console.log('error');
});
}
My backend APi delete function
public function actionDelete() {
switch ($_GET['model']) {
// Load the respective model
case 'users':
$model = User::model()->findByPk($_GET['id']);
break;
default:
$this->_sendResponse(501, sprintf('Error: Mode <b>delete</b> is not implemented for model <b>%s</b>', $_GET['model']));
Yii::app()->end();
}
// Was a model found? If not, raise an error
if ($model === null)
$this->_sendResponse(400, sprintf("Error: Didn't find any model <b>%s</b> with ID <b>%s</b>.", $_GET['model'], $_GET['id']));
// Delete the model
$num = $model->delete();
if ($num > 0)
$this->_sendResponse(200, $num); //this is the only way to work with backbone
else
$this->_sendResponse(500, sprintf("Error: Couldn't delete model <b>%s</b> with ID <b>%s</b>.", $_GET['model'], $_GET['id']));
}
}