Can I replace a <div>
with external php script. Something like this:
$('#aside').replaceWith('blocks/filename.php');
Please be gentle I have just started to learn JavaScript.
UPDATE:
I want to replace that <div id="aside">
. I want to remove it pletely and place the new content there.
Can I replace a <div>
with external php script. Something like this:
$('#aside').replaceWith('blocks/filename.php');
Please be gentle I have just started to learn JavaScript.
UPDATE:
I want to replace that <div id="aside">
. I want to remove it pletely and place the new content there.
-
1
no, you cannot do that for obvious reasons. What you can do, is to make an ajax call to that php page, and based on the response, replace
#aside
div. – Twisted1919 Commented Jul 2, 2013 at 13:07 -
3
Not like that, no, but have a look at the
.load
ajax method – Bergi Commented Jul 2, 2013 at 13:07 -
Use either
.load()
to fetch the contents and load them directly into a holder element, or use.ajax()
(or.get()
, which really is just a shorthand) to fetch the content, then manually put it inside the holder. – qwerty Commented Jul 2, 2013 at 13:11
3 Answers
Reset to default 6You can do this - if you want to replace
#aside
with new content
$.get("blocks/filename.php", function(data) {
$('#aside').replaceWith($(data));
});
Not that simply, you can load your PHP into said div tho with a simple .load
call:
$("#aside").load("blocks/filename.php", function() {
console.log("I've been loaded!");
})
API Ref: http://api.jquery./load/
Per the edits, you'll want to use a $.get
function with a callback to replace that div with the new content.
You want to load the contents from a PHP-file, and put it inside a <div>
right?
The very easy way would be to send a AJAX GET-request to the file, and fill the contents as such:
$.ajax({
url: 'blocks/filename.php',
data: {},
success: function(data) {
$('#aside').replaceWith(data);
}),
dataType: 'html'
});
EDIT: Changed to replaceWith() instead, as suggested.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745067517a4609341.html
评论列表(0条)