简体   繁体   中英

Why is Yii giving my 400 Bad Request?

For some reason I'm getting 400 Bad Request when calling a controller.

This functions works fine and returns data:

lib.getAjax('/address/getDuplicates','').done(function(response){});

This functions however triggers a 400 Bad Request :

lib.setAjax(url,data).done(function(response){});

My route looks like this:

'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

And my functions in AddressController looks like this:

public function actionGetDuplicates(){
    $result = Address::getDuplicates();
    ApplicationPlugin::sendAjaxResponse($result);
}

public function actionMergeDuplicates(){
    $requestData = ApplicationPlugin::getRequestData(array('primaryStreetID, selectedRows'));
    $result= Address::mergeDuplicates($requestData->primaryStreetID, $requestData->selectedRows);

    ApplicationPlugin::sendAjaxResponse($result);
}

So I found my error.

In my controller I was doing this:

$requestData = ApplicationPlugin::getRequestData(array('primaryStreetID, selectedRows'));

when I must do this:

$requestData = ApplicationPlugin::getRequestData(array('primaryStreetID', 'selectedRows'));

This is what caused the 400 bad request

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM