1

用户填写输入文本,按下按钮提交。数据发送到服务器进行存储并返回结果。显示结果的 Fancybox 窗口出现。我的问题是:如何在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,
            }
        );
    }
});

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

好的,仍然不起作用(在fancybox中返回整个页面+顶部的单词“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({
    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 回答