Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将变量从服务器传回ajax成功_Javascript_Jquery_Ajax_Fancybox - Fatal编程技术网

Javascript 将变量从服务器传回ajax成功

Javascript 将变量从服务器传回ajax成功,javascript,jquery,ajax,fancybox,Javascript,Jquery,Ajax,Fancybox,用户填写输入文本,按下提交按钮。数据发送到服务器进行存储并返回结果。显示带有结果的Fancybox窗口。我的问题是:如何在fancybox中显示结果$res1 $.ajax({ type:"POST", url:"index/success", async:false, data:{ name:name, password:password}, success:function () { var html='$res1 from t

用户填写输入文本,按下提交按钮。数据发送到服务器进行存储并返回结果。显示带有结果的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.
?>
============= 新更新: 固定的!!!问题是,数据(上面示例中的“hello”)被发送到框架中的模板,并且显示了模板。 这就是为什么。 固定的。 非常感谢。 每个人。

$.ajax({
$.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);
  }
});
类型:“POST”, url:“索引/成功”, async:false, 数据:{name:name,password:password},
成功:函数(html){/假设您使用的是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);
    }
});

祝你好运!

不幸的是,仍然无法正常工作。我将更新的代码放在问题之后的问题正文中。它返回整个html页面+消息,而不是仅返回消息。
$.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);
    }
});