<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?
-
provide js code of purchaseEntry() and where u display this?sandeep– sandeep2012年03月03日 10:12:04 +00:00Commented Mar 3, 2012 at 10:12
-
2javascript and php are run in different environments. The only possible interaction between them is AJAXMolecular Man– Molecular Man2012年03月03日 10:12:09 +00:00Commented 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?BenOfTheNorth– BenOfTheNorth2012年03月03日 10:12:20 +00:00Commented 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?Gareth– Gareth2012年03月03日 10:12:29 +00:00Commented 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?Mark Baker– Mark Baker2012年03月03日 10:12:47 +00:00Commented Mar 3, 2012 at 10:12
2 Answers 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>
2 Comments
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.