I currently call a PHP script from javascript and return the json data. This works great from the client. I need to make the same call to the PHP script from inside another PHP file. Can this be done?
My current jquery call looks like this:
$.post('functions/get_testdata.php?type='+Type, function(data) {
....
});
From inside another PHP script I’d like to call:
'functions/get_testdata.php?type='.$type
I could just copy the contents of get_testdata to my other PHP page but I’d like to maintain just one code block for this.
Any thoughts or am I missing the obvious?
Yes, You could use something like cURL to do what you want to do, however I would suggest that a better approach might be to encapsulate the logic on that page into a class or function. So that when you call that page you might do something like
You could then call this new function (or class) from anywhere in your code and just pass it the parameter you want.