Jquery州待定

时间:2013-12-11 05:41:59

标签: jquery ajax

在使用Jquery发出ajax请求时,我遇到了一些奇怪的行为,请求永远处于“挂起”状态。

你可以看到我恢复了200 Ok状态,但我不知道它还想要什么。

任何帮助都会受到欢迎。

这是一个非常简单的GET请求:

function validateZipcode(event){
  definitionObj = j(this).data("definition");
  url = baseUrl+"/address/ajax/validateZip/zipcode/"+this.value;
  ajaxObj = j.ajax({url: url,success:function(result){
     handleValidateZip(result.evalJSON(),definitionObj);
  }});
 } `

原始HTTP响应标头如下:

HTTP/1.1 200 OK
Date: Wed, 11 Dec 2013 05:30:30 GMT
Server: Apache/2.4.4 (Unix) PHP/5.4.19 OpenSSL/1.0.1e mod_perl/2.0.8-dev Perl/v5.16.3
X-Powered-By: PHP/5.4.19
Set-Cookie: DBGSESSID=1%3Bd%3D1%2Cp%3D0; path=/; version=1
frontend=1jtnhn5g02vt7nhvmm0ekomb55; expires=Wed, 11-Dec-2013 06:30:31 GMT; path=/somePath;     domain=SomeDomain.com; httponly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
P3p: CP="CAO PSA OUR"
Status: 200 OK
Content-Length: 96
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/json

内容如下:     {"city":"N\/A","state":"DISTRITO FEDERAL","colonies":["HERMANOS SERDAN","PERIODISTA"],"ok":true}

编辑:我不认为服务器端代码在这种情况下是相关的,但在这里它是:

 class GattacaWebLab_Addressvalidation_AjaxController extends Mage_Core_Controller_Front_Action
    {

        /**
        * Returns a JSON object with the state corresponding to the zip and cities that belong to the zip
        * @throws Exception
        */
        public function validateZipAction()
        {
            $zipcode=$this->getRequest()->getParam('zipcode');

            $colonyCollection = Mage::getModel('addressvalidation/colony')->getCollection();
            $colonyCollection->addFieldToFilter('ZIP', $zipcode);
            $cityName=$colonyCollection->getFirstItem()->getCity()->getData('CIUDAD');
            $stateName=$colonyCollection->getFirstItem()->getState()->getData('ESTADO');
            $colonies = array();

            foreach($colonyCollection as $colony)
            {
                $colonies[]=$colony->getData('COLONIA');
            }

            if(sizeof($colonies)>0)            
                $response = array('city' => $cityName, 
                    'state' => $stateName,
                    'colonies'=>$colonies,
                    'ok' => true,
                );
            else
                $response = array('ok'=>false);

            $response=Mage::helper('core')->jsonEncode($response);

            $this->getResponse()
            ->setHeader("Status","200 OK",true)
            ->setHeader('Content-Type', 'application/json')
            ->setBody($response);

            //And voilá mon ami! C'est fini


        }

    }

1 个答案:

答案 0 :(得分:0)

跳出三种可能性:

  1. 您没有从baseUrl加载页面,因此您收到了跨源错误。
  2. Ajax处理中发生错误,但您没有错误回调,因此它已被静音。
  3. 你的成功回调中有一个错误(结果对象真的有一个getJSON函数吗?),你没有注意到。