incorporate asynchronous javascript post requests into php class file -
I inherited a website with an obscure PHP framework called syndrome for which I did not find any documents But problem I'm trying to solve for a good PHP developer.
I am trying to create AJAX requests from javascript in a php file to execute a special function. Ajax request is simply:
loadNewImage = function () {$ .ajax ({url: '/app/library/Controller/Reel.php', data: {action: 'test'} , Type: 'post', success: function (warning) {warning (output);}}); }
The existing PHP file is structured in such a way:
& lt ;? Php square controller_ area protects BaseController_Web {protected function defaultAction () {parent :: getPage ($ This-> template, 'home'); $ Homepage = Homepage :: getInstance () - & gt; GetHomepage (); $ This- & gt; Template-> Title = 'home'; $ This- & gt; Template-> Image = $ homepage ['asset_image']; $ This- & gt; Template-> Center = array ('reel'); $ This- & gt; SetResponse ($ this-> Template); }}
What I want to do is add an investigation to the post data in the file. I'm not good with PHP, but I tried:
Title = 'home'; $ This- & gt; Template-> Image = $ homepage ['asset_image']; $ This- & gt; Template-> Center = array ('reel'); $ This- & gt; SetResponse ($ this-> Template); }}
I am thinking that post data may not be examined within the class, but I am not sure how to configure the code. Can anyone help me straighten up?
Update: I have a file ControllerSite. Php -> (from which baseController_Web is expanded:
protected function Reply () {switch ($ the-> feedback_type) {case itself: RESPONSE_PAGE: // always the latest rendering engine case Attempts to use oneself: RESPONSE_TEXT: Helper_Request :: response ($- >-- processed_response, Helper_Request :: RESPONSE_PRINT, config: $ platform); breaks; case self: reply-response_json: helper_report :: answer ($ This-> Processed Process, Helper_Request :: ReplyPage_Jason, Config :: Plate Form); break; case self: RESPONSE_REDIR: Helper_Request :: response ($ this-> processed_response, helper_revest :: RESPONSE_REDIR, config: $ platform); break; case self :: RESPONSE_CONTENT: // TODO: we have to find out , But now there is no need to worry about it;} $ this return;}
and then in Controller.php (of which ControllerSite.php is extended), it:
Perform the last personal function () {$ action = $ this- & gt; GetMethodName (); $ Is_ajax = Helper_Request :: isAjax (); $ Data_type = stroller (help_release) :: set default ($ _ server ['HTTP_ACCEPT'], '')); If ($ is_ajax and preg_match ('/ \ w + \ / json | w + \ / javascript / i', $ data_type) and amp; method_ exists ($ this, $ action. 'JsonAction')) / This was an Ajax Jason request and Ajax JSSSon specific method exists, execute it $ -> $$ takes action. 'JsonAction'} (); } $ This return; }
Try it out:
class controller_relevance Expansion BaseController_Web {Safe Function Default Action () {Origin: getPage ($ this- & gt; Template, 'Home'); $ Homepage = Homepage :: getInstance () - & gt; GetHomepage (); $ This- & gt; Template-> Title = 'home'; $ This- & gt; Template-> Image = $ homepage ['asset_image']; $ This- & gt; Template-> Center = array ('reel'); If (isset ($ _ POST ['action']) & amp; empty! ($ _ POST ['action'])) {$ reponse ['success'] = true; $ Response ['responseVal'] = 'This is a test'; $ This- & gt; SetResponse ($ response); } And {$ this- & gt; Set Response ($-this-> Template); }}}
Comments
Post a Comment