I'm going a little crazy here as I'm at a real loss for words what is happening. After a lot of digging around, I believe I am doing everything as should be.
我在这里有点疯狂,因为我正在真正失去言语所发生的事情。经过大量的挖掘,我相信我正在尽一切努力。
Situation
I'm trying to send a user creation form to the server via AJAX and codeIgniter fails to even get past this part
我正在尝试通过AJAX将用户创建表单发送到服务器,而codeIgniter甚至无法通过此部分
if($this->input->post('blnAjax')) { // do something }
I have successfully incorporated the AJAX side of things in to the client as it fetches content from the server with very little problem. Here are some of the details involved in the call:
if($ this-> input-> post('blnAjax')){//做某事}我已成功将AJAX方面的内容整合到客户端,因为它从服务器获取内容时几乎没有问题。以下是电话中涉及的一些细节:
Ajax code
The ajax code is part of a much larger framework beyond the scope of this question but in terms of the actual call function, the event has event.preventDefault(); event.stopImmediatePropagation();
to stop it running off. The URL is reachable and the post values have been serialized with request type set to POST
ajax代码是超出此问题范围的更大框架的一部分,但就实际调用函数而言,事件具有event.preventDefault(); event.stopImmediatePropagation();阻止它跑掉可以访问URL,并且已将请求类型设置为POST的序列化后置值
requestpage: function(){
var strURL = params.strBaseURL + params.strRequestURL;
$.ajax({
type: params.strRequestMethod,
url: strURL,
data: params.strRequestParameters,
dataType: 'json',
success: function(json) {
methods.postrequestprocedure(json);
}
});
},
Ajax request
Everything runs smoothly on the client making the XMLHttpRequest with json as expected return. I don't even get to this point when the form has been submitted however. Codeigniter will never think the form has been set if using AJAX
一切都在客户端上顺利运行,使用json作为预期返回的XMLHttpRequest。但是,在提交表单时,我甚至没有达到这一点。如果使用AJAX,Codeigniter永远不会认为已经设置了表单
Parameters application/x-www-form-urlencoded
blnAjax 1
user_login_name[] fred
user_login_name[] ted
user_name[] Fred Flintstone
user_name[] Ted bear
usergroup_id[] 16
usergroup_id[] 16
Controller
On the controller, with regard to the action, I have included alall code up to the point of fail. Please note that I have tested the other aspects of the code and they run fine
在控制器上,关于动作,我已经包含了一些代码,直至失败。请注意,我已经测试了代码的其他方面,它们运行正常
public function user_add() {
/* Include extra script files needed for form handling */
$this->view['aryScript'][] = 'jquery.validate.min';
$this->view['aryScript'][] = 'jquery.validate.additional-methods';
/* Include extra CSS files */
$this->view['aryCSS'][] = 'form';
/* First check if the user has correct access rights */
if($this->view['intAccessLevel'] < INT_SUPER_USER_ACCESS_LEVEL) {
$aryResponse['notifications'][] = array('strType' => 'permanent',
'strMessage' => 'Denied!');
}
/* Import extra libraries and helpers */
$this->load->library(array('PasswordHash'));
$this->load->model('UserAdminModel');
$this->view['strTitle'] = 'Add User';
$this->view['aryButtons']['user_add_another'] = array(
'strDisplay' => $this->lang->line('user_add_another')
'strURL' => '#',
'strID' => 'user_add_another',
'aryData' => array('action' => 'form-clone')
);
if($this->input->post('blnAjax')) {
echo 'Big sigh of relief';
Thank you kindly for taking the time to read my problem
谢谢你花时间阅读我的问题
1 个解决方案
#1
0
The answer is never as simple as it seems! My client is using a CodeIgniter mod that rewrites the URI and thus dumping the data passed from the ajax query. It hadn't been a problem when performing gets and "real" POST queries.
答案绝不像看起来那么简单!我的客户端正在使用CodeIgniter mod来重写URI,从而转储从ajax查询传递的数据。执行获取和“真正的”POST查询时,这不是问题。
So if you are ever using Wiredesignz - Language Identifier beware that it can affect your queries
因此,如果您曾经使用过Wiredesignz - 语言标识符要注意它会影响您的查询
How I fixed it, I use a custom page controller but the theory is the same:
我如何修复它,我使用自定义页面控制器,但理论是相同的:
- Be sure that you have
$this->config->item('language_abbr');
available to your javascript functions maybe through a constant or echo it directly in to the javascript if on the same page - Modify the URL before sending it with something similar to
params.strBaseURL + params.strLanguage + '/' + params.strRequestURL;
确保你有$ this-> config-> item('language_abbr');可用于您的javascript函数可能通过常量或直接回显到javascript,如果在同一页面上
在发送URL之前修改URL,类似于params.strBaseURL + params.strLanguage +'/'+ params.strRequestURL;
You should now find things work just fine. I hope this helps and noone else has to spend a mini eternity to find this out
你现在应该发现工作正常。我希望这有帮助,没有其他人必须花费一个小小的永恒才能找到它
#1
0
The answer is never as simple as it seems! My client is using a CodeIgniter mod that rewrites the URI and thus dumping the data passed from the ajax query. It hadn't been a problem when performing gets and "real" POST queries.
答案绝不像看起来那么简单!我的客户端正在使用CodeIgniter mod来重写URI,从而转储从ajax查询传递的数据。执行获取和“真正的”POST查询时,这不是问题。
So if you are ever using Wiredesignz - Language Identifier beware that it can affect your queries
因此,如果您曾经使用过Wiredesignz - 语言标识符要注意它会影响您的查询
How I fixed it, I use a custom page controller but the theory is the same:
我如何修复它,我使用自定义页面控制器,但理论是相同的:
- Be sure that you have
$this->config->item('language_abbr');
available to your javascript functions maybe through a constant or echo it directly in to the javascript if on the same page - Modify the URL before sending it with something similar to
params.strBaseURL + params.strLanguage + '/' + params.strRequestURL;
确保你有$ this-> config-> item('language_abbr');可用于您的javascript函数可能通过常量或直接回显到javascript,如果在同一页面上
在发送URL之前修改URL,类似于params.strBaseURL + params.strLanguage +'/'+ params.strRequestURL;
You should now find things work just fine. I hope this helps and noone else has to spend a mini eternity to find this out
你现在应该发现工作正常。我希望这有帮助,没有其他人必须花费一个小小的永恒才能找到它