ajax成功内的ajax [英] ajax inside an ajax success
问题描述
我建立了一个ajax网站,它从我的index.php中的/pages
文件夹中的/pages
文件夹调用php页面,我的页面painting.php
中有一个调用painting-slider.php
页面的链接.
i made an ajax website that call php pages from a /pages
folder inside my index.php, inside my page painting.php
i have a link that call painting-slider.php
page.
那么当我已经调用我的painting.php页面时,如何在Ajax中打开此painting-slider.php
?
so how can i open this painting-slider.php
in ajax when i already called my painting.php page?
这是我的index.php请求页面:
this is my index.php request page:
<div id="ajax-container">
<?php
$d = "pages/";
if (isset($_GET['p'])) {
$p = strtolower($_GET['p']);
if (preg_match("/^[a-z0-9\-]+$/", $p) && file_exists($d . $p . ".php")) {
include $d . $p . ".php";
} else {
include $d . "404.php";
}
} else {
include $d . "home.php";
}
?>
</div>
这是我的ajax函数:
and this is my ajax function:
var afficher = function(data, page) {
$('#ajax-container').fadeOut(250, function() {
$('#ajax-container').empty();
$('#ajax-container').append(data);
$('#ajax-container').fadeIn(100, function() {});
});
};
var lastRequest = null;
if (lastRequest !== null) {
lastRequest.abort();
}
var loadPage = function(page, storeHistory) {
if (typeof storeHistory === 'undefined') {
storeHistory = true;
}
lastRequest = $.ajax({
url: "pages/" + page,
cache: false,
success: function(html) {
afficher(html, page);
if (storeHistory === true) {
history.pushState({
'key': 'value',
'url': page
}, '', page);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
afficher('erreur lors du chagement de la page');
}
});
return false;
};
window.addEventListener('load', function() {
setTimeout(function() {
window.addEventListener('popstate', function(e) {
if (e.state === null) {
loadPage('home.php');
} else {
loadPage(e['state']['url'], false);
}
});
}, 0);
});
$('.link').bind('click', function(e) {
e.preventDefault();
var page = $(this).attr('href');
loadPage(page);
return false;
});
推荐答案
"ajax之后的ajax"的简单示例:
a simple example of "ajax after ajax":
$.ajax({
url: "pages/" + page,
cache: false,
success: function(html) {
afficher(html, page);
if (storeHistory === true) {
history.pushState({
'key': 'value',
'url': page
}, '', page);
}
$.ajax({
url: otherUrl,
cache: false,
success: function(result) {
alert("i am the second result");
alert(result);
}
});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
afficher('erreur lors du chagement de la page');
}
});
在服务器端(您的PHP文件)执行任何操作并不重要.您的ajax只会获取在给定Urls处找到的脚本的返回值.希望对您有帮助
On the serverside (your PHP files) it is not important to do anything. Your ajax will just get the return value of the script found at the given Urls. I hope it helps
这篇关于ajax成功内的ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!