用户填写输入文本,按下按钮提交。数据发送到服务器进行存储并返回结果。显示结果的 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”)被发送到框架中的模板,并显示模板。这就是为什么。固定的。谢谢你。大家。