所有網頁 圖片 影片 地圖 新聞 網誌搜尋 Gmail 更多 »
最近造訪的群組 | 說明 | 登入
Google 網上論壇首頁
Help returning JSON
目前本群組有太多主題設為優先顯示。要優先顯示這個主題,請將其他主題的這個選項取消。
在處理您的要求時發生錯誤。請再試一次。
標幟
  4 個訊息 - 全部摺疊  -  將全文翻譯為 已翻譯 (查看所有原文)
您要留言的群組是 Usenet 群組。在此群組留言,網際網路上的任何使用者將可以看到您的電郵地址。
您的回覆郵件尚未寄出。
您已成功留言
 
寄件人:
收件人:
副本:
後續追蹤對象:
新增副本 | 新增後續追蹤對象 | 編輯主旨
主旨:
驗證:
為了確認,請輸入您在以下圖片中看到的字元,或輸入您按下存取圖示時所聽到的號碼。 注意聽並輸入您聽到的號碼
 
Dave  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月7日, 上午12時35分
寄件人: "Dave" <make.cake.b...@gmail.com>
日期: Fri, 6 Nov 2009 13:05:46 -0330
當地時間: 2009年11月7日(星期六) 上午12時35分
主旨: Help returning JSON
I have setup a validation rule using jquery to check if a field is valid by
an ajax request.

The controler checks and returns valid (true or false). I watch the activity
using firebug and the request gets sent fine, and i see whats sent and comes
back in the response. But it is not returning correct.
I test with my personal valid email address or a real email address I have
in the db should come back to check because the one in the db should return
false because it exists, and the one that's not in the db should come back
validbut its always false.

POST TAB:
data[Profile][email]    mytestem...@mytestsite.com

RESPONSE TAB:
{"valid":false}

JSON TAB:
false

CONTROLLER FUNCTION:
function manage_validate() {
   $this->autoRender = false;
          Configure::write('debug', 0);
          if ($this->RequestHandler->isAjax()) {
   //debug($this->data);
   $this->Profile->set($this->data);
              if ($this->Profile->validates()) {

      header("Content-type: text/plain");
       $valid = true;
       $array = array('valid' => $valid);
       echo json_encode($array);

              } else {
       header("Content-type: text/plain");
       $valid = false;
       $array = array('valid' => $valid);
       echo json_encode($array);
                  //$errors = $this->Profile->invalidFields();
                      //debug($errors);

              }

          }
      }

Ideas where I am going wrong?

Thanks
Dave


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
Kyo  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月7日, 上午10時12分
寄件人: Kyo <ready2jam2n...@gmail.com>
日期: Fri, 6 Nov 2009 18:12:37 -0800 (PST)
當地時間: 2009年11月7日(星期六) 上午10時12分
主旨: Re: Help returning JSON
You don't have to use header() and json_encode() to get JSON values
back with Cake.
Use $this->layout = 'ajax' in your controller and $javascript->object
() in your view.
Try out my way: http://jamnite.blogspot.com/2009/05/cakephp-form-validation-with-ajax...

hth,

Kyo


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
Dave  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月8日, 上午12時06分
寄件人: "Dave" <make.cake.b...@gmail.com>
日期: Sat, 7 Nov 2009 12:36:52 -0330
當地時間: 2009年11月8日(星期日) 上午12時06分
主旨: RE: Help returning JSON
Thanks for your response.

I did take a look at your tutorial. But in my situation  I don't think a lot
of what you have there will apply to me. I have everything to a point
working. Right now I am only trying to validate one field using validate:
remote option to check if a user email is already registered.

The data[User][email] = myt...@dummy.com gets sent to Cake . If I debug
error I see

Array
(
    [email] => This email account is already registered.
)

I just need a way to get the error or success back to the js remote part of
the script...thats where I am lost.

I am not sure how to send back the message if there is an error or if valid
do nothing.

I tried using your suggestion with layout ajax but all I ended up getting
was an error messages showing {valid : false} where "This email account is
already registered." Should go.

My js validate rule looks like:

var validate_profile = {

        rules: {
                        'data[Profile][email]':{required: true, email:true,
remote: {url: "/manage/profiles/validate",type: "post"}},
        },
        messages: {

                'data[Profile][email]': {
                        required: '* JS required email address.',
                        email: '* JS email address.',
                        remote: '* this message is remote from JS.'}
        }};

And my controller:

function manage_validate() {
          Configure::write('debug', 2);
          if ($this->RequestHandler->isAjax()) {
                        $this->Profile->set($this->data);
              if ($this->Profile->validates()) {
                           //nothing to do

              } else {
                            //header("Content-type: text/plain");
                        $errors = $this->Profile->invalidFields();
                        //debug($errors);

                        $array = array("valid" => false);

                        return json_encode($array);

                        //$this->set('output' , $output);
                        //echo json_encode($array);
               //$this->layout = 'ajax';  
               //$this->render ('/elements/errors/ajax_fields');
              }

          }
      }

Ajax_fields.ctp :

<?php echo $javascript->object($output);?>

Any ideas?

Thanks again

Dave


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
Miles J  
檢視個人資料   翻譯為 已翻譯 (查看原文)
 更多選項 11月8日, 上午4時08分
寄件人: Miles J <mileswjohn...@gmail.com>
日期: Sat, 7 Nov 2009 12:08:35 -0800 (PST)
當地時間: 2009年11月8日(星期日) 上午4時08分
主旨: Re: Help returning JSON
Because your sending the wrong header, if your returning JSON it
should be the JSON header...

header("Content-type: application/json");

On Nov 7, 8:06 am, "Dave" <make.cake.b...@gmail.com> wrote:


    回覆    回覆作者    轉寄  
您必須先登入才能張貼訊息。
若要張貼訊息,您必須先加入此群組
請在留言之前更新您訂閱設定網頁上的暱稱。
您沒有留言所需的權限。
無其他留言
« 返回討論主題 « 較新的主題     較舊的主題 »

建立群組 - Google 網上論壇 - Google 首頁 - 服務條款 - 隱私權政策
©2009 Google