【发布时间】:2016-04-21 06:31:28
【问题描述】:
我有一个将表单数据与文件一起提交到控制器的 ajax,控制器将使用 curl 将此表单数据发送到我的 api。我该怎么做?
我不能直接将表单提交到我的 api,它必须通过我的控制器。 :(
我的 ajax
data = new FormData();
data.append( 'file', $( '#file' )[0].files[0] );
data.append( 'title', title );
data.append( 'description', description );
data.append( 'module_id', module_id );
data.append( 'tags', tags );
data.append( 'groups', groups );
$.ajax({
url: '/controller/upload',
data: data,
processData: false,
contentType: false,
type: 'POST',
success: function ( data ) {
window.location.reload();
}
});
我的控制器功能
public function uploadAction(){
$response = new \Phalcon\Http\Response();
$response->setContentType('application/json', 'UTF-8');
$response2 = "{}";
if($this->request->getPost()){
$version = $this->session->get("version");
$data = $this->request->getPost('data');
$response2 = $this->useCurl("api_link","POST",$data);
}
return $response->setContent($response2);
}
【问题讨论】:
-
$this->useCurl是做什么的?