0
<a href="#" onclick="return purchaseEntry('39873');">ABC</a>

I'm planning to crawl to a web page and fetch certain contents using regex. However, this content only shows up after onclick is activated. I need to get into ABC and fetch the content. I can't use file_get_content() because there is no link takes me to ABC page. ABC content shows up when user clicks it. Results are called via Javascript/Ajax/Json.

ABC contents are:

Name: XXXX
Address: XXXXXX

Any idea how to crawl to ABC and fetch the content?

Note: I will have to write a PHP script that crawls into remote page and fetch ABC content.

Extra info:

function purchaseEntry(customerid) {
 $('customeridfield').value = customerid;
 if (approvedAgents()) {
 e1 = $('entrylisttable');
 e1.hide();
 getExistingDetails(customerid, 'confirmstatusexistingdetails');
 $('confirmstatushajjlicenceno').value = '';
 $('confirmstatusapproved').checked = false;
 e1 = $('confirmstatus');
 e1.show();
 }
 return false;
}

Also here is getExistingDetails:

function getExistingDetails(customerid, existingdetails) {
 e1 = $(existingdetails);
 e1.innerHTML = 'Loading ... <img src="/jpg/ajaxloader.gif" />';
 var url = '/samex/index.php';
 var pars = 'option=com_directory&view=entry2&customerid=' + customerid + '&format=raw';
 new Ajax.Request(url, { method: 'get', parameters: pars,
 onSuccess: function(request) {
 var json = request.responseText.evalJSON();
 jsondata = json['data'];
 e1 = $(existingdetails);
 e1.innerHTML = jsondata['clientdata'];
 },
 onFailure: function(request) {
 e1 = $(existingdetails);
 e1.innerHTML = 'Unable to get information for customer ' + customerid;
 }
 });
}

Any suggestions?

asked Mar 3, 2012 at 10:08
11
  • provide js code of purchaseEntry() and where u display this? Commented Mar 3, 2012 at 10:12
  • 2
    javascript and php are run in different environments. The only possible interaction between them is AJAX Commented Mar 3, 2012 at 10:12
  • Not quite sure I get what you mean - do you want to basically pull this function name (and value) from a remote page, and then... run it? Commented Mar 3, 2012 at 10:12
  • I'm not sure I understand...PHP runs on the server, the onclick attribute runs javascript on the client. How are you getting your return value to PHP? Commented Mar 3, 2012 at 10:12
  • So where's the actual code.... all we see is the trigger. WHere's the js purchaseentry() function, and the corresponding php code? Commented Mar 3, 2012 at 10:12

2 Answers 2

2

You can't run JavaScript events from PHP. PHP is a server-side language, whereas HTML and JavaScript are client side languages.

The only way you can get data from the client side HTML and JavaScript is to use one of the following methods:

Use an HTML form with an action to submit data back to the server.

 <form action="/submit.php">
 <input name="purchaseEntry" value="39873" />
 <input type="submit" value="Submit" />
 </form>

Use an AJAX call to send data to the server without having to reload the page.

 // jQuery ajax
 $.ajax({"url" : "/submit.php", 
 "type" : "post",
 "data" : "purchaseEntry=" + document.getElementById("purchase-entry")
 "success" : function() {
 alert("data sent to server");
 }
 );

Pull data from the $_REQUEST object when the user navigates to a different page. This assumes your data is in the link.

 <p><a href="/page2.php?purchaseEntry=39873">Page 2</a></p>
answered Mar 3, 2012 at 10:20
Sign up to request clarification or add additional context in comments.

2 Comments

Most crawlers aren't going to be able to read DHTML (Dynamic HTML). In general, your crawler will only see the RAW HTML. You could however figure out what the URL is that is called when one clicks the link in the remote page, bypassing the UI completely. Unless the remote server returns JSON with padding, you'll need to fetch it from your server to avoid cross-domain restrictions.
Quick msg: After using firebug, i found that all contents i need resides in e1.innerHTML = jsondata['clientdata']; ...
2

Your purchaseEntry('39873') can contain an ajax call to your php file.

You php file can then respond with a json converted from an array using echo json_encode($yourArray)

Then your ajax call can reconvert it into Javascript array/object from the received json string from php.

answered Mar 3, 2012 at 10:13

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.