How to handle Ajax request with MVC in PHP -


I am currently working on my own MVC framework in PHP. I want to know how to deal with Ajax requests ...

URI created a page using www.domain.com/controller/method/params

URI is a The router is passed through the class, which receives the controller and methods + parameters to use

It looks good yet, but I also have a header and footer, maybe the original page But there will also be a sidebar and the main content of the MVC page Part will fill.

When I make an Ajax request, for example, www.domain.com/user/create: Controller = user method = create

for example I Trying to create the whole page as it is sending one

P> Here are some incomplete answers. Here's how you do it, it's very easy ...

What you're doing is checking for AJAX header and depending on it, Different content Does not. AJAX header:

  $ _ server ['http_X_REQUESTED_WITH']   

It will be set to XMLHttpRequest for AJAX requests After all major JavaScript libraries there is a standard .

When I make an Ajax request, for example www.domain.com/user/create: Controller = User Method = Create

Therefore, By knowing this, we can check for the AJAX header in your method and output the output accordingly.

  to create a user // code (isset ($ _SERVER ['HTTP_X_REQUESTED_WITH']) & amp; amp; and strtolower ($ _SERVER ['HTTP_X_REQUESTED_WITH'] ']) ==' xmlhttprequest ') {// New User ID return in Jason format (xml) die (json_encode (array (' user_id '=> gt; new_user_id)); } // hearing of load ideas}}    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -