1

I am trying to replace an iframe, essentially. I would like to load the result of a php page into a div. The results are being parsed through URL - http://example.com/view.php?id=1 - for exmaple. Sorry, I don't have much experience with javascript.

The closest example I could find is here: http://www.w3schools.com/PHP/php_ajax_database.asp

But that is for a select box.

Could anyone else possibly?

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
elzi
  • 5,442
  • 7
  • 37
  • 61
  • 1
    You can do that more easily with jQuerys [`$.load()`](http://api.jquery.com/load/) method. There it's just `$("div#id").load("http://url...");`. But of course you can do it the manual JS way.. (The w3schools example isn't as bad as usual.) – mario Jan 14 '12 at 04:14
  • possible duplicate of [How do I load a page in a div?](http://stackoverflow.com/questions/6112846/how-do-i-load-a-page-in-a-div) – mario Jan 14 '12 at 04:16
  • I'm still confused on how to use it in a link :-/ Considering different links will have different IDs. Here's a jsFiddle I set up: http://jsfiddle.net/JY7ZK/ – elzi Jan 14 '12 at 05:01

1 Answers1

3

If you want to use it as a link then the lazy solution is:

<div id=content> loaded page goes here </div>

<a onclick="$('div#content').load('http://example.org/ajax.php?id=1')">click</a>

Or even with the good ol javascript pseudo URI:

<a href="javascript:$('#id').load('url')">click</a>
mario
  • 144,265
  • 20
  • 237
  • 291
  • No idea either. That looks good. Except that `.load()` is also susceptible to same-origin policies. It's not an iframe replacement, can only load content from the same server. (AFAIK) – mario Jan 14 '12 at 05:12