1

ユーザーが入力テキストを入力し、[送信]ボタンを押します。データはサーバーに送信されて保存され、結果が返されます。結果を示すFancyboxウィンドウが表示されます。私の質問は、結果$res1をファンシーボックスに表示する方法です。

$.ajax({
    type:"POST",
    url:"index/success",
    async:false,
    data:{ name:name, password:password},
    success:function ()
    {
        var html='$res1 from the server should be here instead of this string';//var html=$res1.
        $.fancybox(
            {
                content: html,//fancybox with content will be displayed on success resul of ajax
                padding:15,
            }
        );
    }
});

=========================

OK、それでも機能しません(ファンシーボックスにページ全体と、メッセージ「hello」の代わりに「hello」という単語が表示されます)。以下は、以下の回答に関する私の更新ですが、正しく機能しません。

PHP:

<?php
    $res1="hello";... // handle logic here
    echo $res1; // print $res1 value. I want to display "hello" in the fancybox.
?>

AJAX

$.ajax({
    type: "POST",
    url: "index/success",
    async: false,
    data: {
        name: name,
        password: password
    },
    success: function (html) {
       $.fancybox(
       {
         content: html,//returns hello+page in the fancybox

          //if I use the string below instead of the upper one, the fancybox shows "The requested content cannot be loaded. Please try again later."
         // content: console.log(html) 


         padding:15,
    }
});

============= 新しいアップデート: 修正されました!!! 問題は、データ(上記の例では「hello」)がフレームワークのテンプレートに送信され、テンプレートが表示されたことです。それが理由です。修理済み。ありがとうございました。みんな。

4

2 に答える 2

1
$.ajax({
  type:"POST",
  url:"index/success",
  async:false,
  data:{ name:name, password:password},
  success:function(html){ // <------- you need an argument for this function
    // html will contain all data returned from your backend.
    console.log(html);
  }
});
于 2012-07-19T15:05:47.877 に答える
1

PHPを使用していると仮定します。

PHP

<?php
    ... // handle logic here
    echo $res1; // print $res1 value
?>

AJAX

$.ajax({
    type: "POST",
    url: "index/success",
    async: false,
    data: {
        name: name,
        password: password
    },
    success: function (html) {
        // given that you print $res1 in the backend file,
        // html will contain $res1, so use var html to handle
        // your fancybox operation
        console.log(html);
    }
});

楽しんで頑張ってください!

于 2012-07-19T15:12:15.233 に答える