简体   繁体   English

从视图将变量发送到控制器:Zend Controller

[英]Sending variables to the controller from the view : Zend Controller

I want to send a set of variables to the controller from the view , but apparently they don t come to the controller, already the success function does not repent, here is the code for sending the niveu of view, knowing that the success function m displays nothing : 我想从视图中向控制器发送一组变量,但是显然它们没有到达控制器,已经成功函数没有后悔,这里是发送视图niveu的代码,知道成功函数m什么都不显示:

$.ajax({ 

     type: "POST", 
     url: "<?php echo $this->url(array('controller' => 'properties', "action"      =>"tasktodo")); ?>",                  
      data: { 
      latitude: position.coords.latitude, 
      longitude: position.coords.longitude, 
      }, 
      success: function(data) { 
      alert ("datalatit"); 
      } 
      }); 

can someone tell me where is the problem ? 有人可以告诉我问题出在哪里吗?

There could be several problems with your request: 您的请求可能存在几个问题:

  1. Make sure that the url is generated correctly. 确保该url正确生成。 Try via hardcoding it just to see. 尝试通过硬编码来查看。 Also debug the output of: echo $this->url(array('controller' => 'properties",..... 还调试以下输出: echo $this->url(array('controller' => 'properties",.....

  2. As @Tim Fountain suggested check if you are sending data (Provided that your request gets through at all) 正如@Tim Fountain建议检查您是否正在发送数据(前提是您的请求完全通过了)

  3. Check if there is something blocking your request? 检查是否有什么阻止您的请求? Security, Authentication, etc. ?? 安全性,身份验证等

  4. Implement the error callback of jQuery's $.ajax(); 实现jQuery的$ .ajax() error回调。 It is there to handle errors and any implementation of an AJAX call should have it. 它在那里可以处理错误,任何AJAX调用的实现都应该包含它。 An example implementation that would "dump" all variables to the console is: 将所有变量“转储”到控制台的示例实现是:

     success: function(data) {......}, error : function (jqXHR, textStatus, errorThrown){console.warn('An error occured!');console.log(jqXHR);console.log(textStatus);console.log(errorThrown);} 

This way you will be able to inspect the error. 这样,您将能够检查错误。 Then implement something to handle it. 然后实施一些处理。

Sorry for the poor format of the code. 抱歉,代码格式不正确。 I had some problem with the editor here.. 我在这里的编辑器有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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