Jump to content
jsantari

Adding an ajax api custom route

Recommended Posts

Trying to do some ajax calls to an api  named somedomain.com/xapi/index.php using intercoolerjs in my home page. I'm trying to make calls like this in intercoolerjs. somedomain.com/xapi/controller/method. Looked through a bunch of the posts but nothing seems to match what I am trying to do. Is there a change I can make to the htaccess file  to get this to work? Anyone have a suggestion on this or is there a better way to handle the api?

Share this post


Link to post
Share on other sites

I looked at some of the posts on that module and it's not what I'm looking for. I can handle the intercoolerjs side fine. I've done a few small projects with it using mysql & slim as the route handler. I can use a simple template in PW like api.php and call url's like somedomain.com/api/?c=controller&m=method but then intercoolerjs can't take advantage of the dependency system. Basically what I'd like is to just be able to route to the subfolder with PW getting out of the way. I can bootstrap PW at that point and do what I want.

Share this post


Link to post
Share on other sites

Do you mean that the PW htaccess is disallowing access to your PHP file (you are getting the 404 page)?

PW blocks direct access to PHP files inside /site/ but you should be able to access it inside the root, e.g.

/api.php

...or...

/xapi/index.php

 

Share this post


Link to post
Share on other sites

Can you explain a bit more why ProcessWire does get in the way of this dependency support? I mean your api could still map to paths using urlSegments.

Share this post


Link to post
Share on other sites

@Robin SIt will go to api.php when that was setup as a template for the page /api. I did figure out that PHP files don't work in /site/ and I moved it to /xapi below root. I can access it now and just figured out how to get what I wanted.

@LostKobrakaiMoving it outside of /site/ as mentioned above got it working with parameters but still didn't get me the ability to use segments. Was able to get that working by adding a rewrite rule in the PW .htaccess. Don't see any other way to get it to work so that will need to go into any updated .htaccess I use down the road.

Share this post


Link to post
Share on other sites
On 13.1.2017 at 7:23 PM, jsantari said:

 I'm trying to make calls like this in intercoolerjs. somedomain.com/xapi/controller/method.

Do you mean...  you want handle the request/url in your template (controller) and take the url segment (method) and map it to a corresponding method in a class of your template?

...like Codeigniter Framework has it? url/xxx/yyy/zzz calls method yyy in controller xxx with zzz as argument?  Or do you just don´t know how to use url segments?

 

here this guy uses this kind of url segments...

 

Share this post


Link to post
Share on other sites
On 1/13/2017 at 7:23 PM, jsantari said:

I'm trying to make calls like this in intercoolerjs. somedomain.com/xapi/controller/method

Also:

 

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Orkun
      Hi Guys
      How can I make a redirect inside the .htaccess to my custom maintenance.html file when any URL of my Website is accessed except the processwire admin (www.example.com/processwire/).
      Because I want that my User's still can access the website when they are loggedin in Processwire.
      When the current url starts with /processwire or if there is a processwire-login-cookie (Is there a cookie when user is logged in Processwire?) available the redirect should not work. Otherwise it should work.
      How can I achieve this?
    • By rushy
      Hello. I have recently adopted PW markup regions and really like this way of working. However, I am also trying to learn how to use Ajax and I am not sure of a good way to use the two together. Has anyone got any experience, tips or hints on using them together? For ajax -  I've used a simple scheme where I have a "webservice" template and page that handles Ajax requests and returns the appropriate content wrapped with some markup for the requesting page. I have markup regions enabled and all my pages (bar webservice) include a _main.php which brings in the headers, a default body and the footer. My javascript intercepts the page links and does my ajax call to webservice and that sends back the appropriate markup which is then placed by in the div #body defined in _main.php.  Does this seem a reasonable way to work? I guess I am looking for some advice before I invest too much time going the wrong way!
      Any guidance, remarks,  comments, or a nudge in the right direction greatly appreciated.
      Paul
    • By gerald
      In my frontend I would like to implement a small AJAX-solution, but it does´nt work. For example:
      template/js/ajax.js: contains jquery-ajax-snippet with click-function like this: $.post('ajax.inc', function(e) {});
      template/ajax.inc: contains db-query with HTML-output
      template/home.php: contains div-element for the ajax-response, e.g. <div id='result'>...ajax-response...</div>
      It seems, PW does´nt allow database-requests via AJAX (jquery). I know the post from Ryan "How to work with AJAX driven content in ProcessWire". But this solution requires a completely new template-concept. I only need a simple solution for a small ajax-db-request.
      Thanks to all
    • By neophron
      Hi there,
      a few weeks ago I completed a 3.098 installation (server php 7.2). Yesterday I wanted to login but failed. I tried different browsers, meanwhile on two different PCs, but no login.
      Then I realized, that after hitting the »Login« button, there was no message (admin name – Login failed). I also tried all procedures (https://processwire-recipes.com/recipes/resetting-admin-password-via-api/). Then I checked the errors.txt (site/assets/logs) – nothing.
      The frontend works fine. Is there a way to check this Processwire installation? Could be something missing?
       
    • By Jennifer Stock
      Greetings. I would like to restrict access to certain sections of my organization's ProcessWire site using pubcookie. We are rolling out Shibboleth authentication later this year but for now, it seems I can only make use of our institution's single sign-on routine by utilizing rules in an .htaccess file. 
      I am wondering if there is a way to ask PW to apply these rules to certain pages in the site, whether via template type or location in the page tree:
      AuthType UWNetID PubcookieAppID "MyApplication" require type staff faculty  
×
×
  • Create New...