Reputation: 2866
<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?
Upvotes: 0
Views: 616
Reputation: 34078
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>
Upvotes: 2
Reputation: 6509
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
.
Upvotes: 2