ユーザーが入力テキストを入力し、[送信]ボタンを押します。データはサーバーに送信されて保存され、結果が返されます。結果を示す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」)がフレームワークのテンプレートに送信され、テンプレートが表示されたことです。それが理由です。修理済み。ありがとうございました。みんな。