How to use Ajax to inject specific PHP function using URL, or other method? -


I am just moving from JS to PHP and Ajax. I have had a dispute with PHP in the past. I appreciate really how Stackworflow is helping to help me with basic questions.

Say I have a device called #divName .

I use the following JS for Ajax. Some of these are just fake codes.

  var request = false; {Request = New XMLHttpRequest (try); } Hold (trymicrosoft) {try {request = new ActiveXObject ("Msxml2.XMLHTTP"); } Hold (other Microsoft) {try {request = new ActiveXObject ("Microsoft.XMLHTTP"); } Hold (failed) {request = false; }}} If (! Request) Warning ("Error Starting XMLHttpRequest!"); Function getAjaxInfo (& lt; name of php function ??? & gt;) {// & lt; & Lt; & Lt; & Lt; & Lt; This function requires me help with var myfunction = nameOfPHPfunctionIJustGot; Var url = "filename.php? Func =" + myFunction; Request.open ("GET", URL, true); request. Request.send (zero); } Function Update Page () {if (request.readyState == 4) {if (request.status == 200) {var response = request.responseText; Document.getElementById ("divName"). InnerHTML = Feedback; // maybe going to add Jquery here, but this example works} Other warnings ("status" + request.status); }}  

I have the fileName.php file:

   

My goal is that when I execute getAjaxInfo () , then I can pull any PHP function I want.

a onClick = "getAjaxInfo (header) " This will get a php header function, apply it to a JavaScript function, and then apply a div

Any help would be appreciated!

Try it with:

  $ function = $ _ received ['Ceremony']; If (function_exists ($ func)) $ func ();  

In this way you get the function name given by GET and execute it.

If you want to be able to call only some functions:

  $ allowedFunctions = array ("title", "footer"); Get $ function = $ _ ['function']; If (in_array ($ func, $ allowed function) and function_exists ($ func)) $ func ();  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -