views:

72

answers:

4

When i need to get a content from a site, i use file_get_content() function, but now i need to grab a data, which loads after ajax request. so i can't mention the exactly url address. are there any algoritms to do such things?

Thanks.

+3  A: 

If i'm understanding your question correctly, you want to do a file_Get_content on a website which loads AJAX data... this is a client side process which happens when the Client's browser hits it, seeing as you're making a server side request you won't see it.

The best thing to do is find the ajax requested information via the NET panel in firebug, and then do a request on that information in a separate file get content call.

Frederico
@Frederico ok, let's assume, i know the function, which makes ajax requset, but how can i call the same function from my script?i have some ideas, but they all are very hard.
Syom
@Syom: It's still a client side call. Your best bet is to visit the website, look at your NET panel in firebug and watch the requests which are made. Find the one you're wanting to grep, and then create your call on that. see: http://michaelsync.net/2007/10/15/firebug-tutorial-section-4-net-css-and-dom-tabs
Frederico
A: 

You might be able to attach to a JavaScript implementation like Rhino, but it'd be a long, painful road.

ceejayoz
A: 

Using the Net Panel in firebug (firefox) or the resources panel in Chromes Developer Tools you can watch the AJAX calls from a specific page. You can then either call that same request in your javascript or use a php script act as a proxy to the page. If you wanted to use the PHP proxy method you could use file_get_contents or cURL for more advanced requests (such as POST data). I would then recommend caching the data so not to upset who ever you are getting the information from and to shorten script execution time.

If the URL of the page containing the data changes then you could use a regular expression to find the URL in the page depending on how it works

Olly Hicks
A: 

It sounds like you want to grab specific content from a page on a remote server. You might consider using jQuery's load() function for this:

$('#my_container').load('local_proxy.php #container');

Your local proxy would handle the file_get_contents() remote call for cross-domain security reasons, but it would load the content from the remote element of id "container" (i.e. <div id="container">) and pass it straight into your "my_container".

Not sure if this is what you're looking for, but it's nice to do so much with one line of js... :P