I would use console.log to log the exact URL right before you call it, then make sure you can access that same URL in your desktop and mobile browsers.
A 404 means you’re trying to access something that isn’t there… So either you are using the wrong URL in your client, or the server is missing files at that location.
I’m just starting out, not sure what code would help…All the code is there in the link I posted - if you can be bothered downloading the zip file and having a look. All I changed is the index.php to index.html, and the full address of ServiceBase as stated above, to work as an ionic app which will be built for android.
I develop using ionic serve, so the url I am viewing my app on locally is http://localhost:8100/#/login
Of course in Firefox I get the following errors:
Cross-Origin
Request Blocked: The Same Origin Policy disallows reading the remote
resource at http://mywebsite.com/myproject/api/v1/login. (Reason:
CORS header ‘Access-Control-Allow-Origin’ missing).2Cross-Origin
Request Blocked: The Same Origin Policy disallows reading the remote
resource at http://mywebsite.com/myproject/api/v1/login. (Reason:
CORS request failed).
And in Chrome, when I disable security (to get past CORS) I just get: the 404 errors…
I do prefer Firefox though, Do you have any tips on getting past CORS?
Do you host the API yourself? I have a wordpress website where I create subfolders for other projects and one project is where I hold my api. Maybe that is the problem?
You do need to make sure you enable CORS on your server, but also have you added the domain to your whitelist within Cordova?
I would also look at proxying your api calls through ionic if you are using ionic serve, as localhost can sometimes also cause issues when developing locally.
In your ionic.project file you’ll need to add a proxies property
authentication.php - this the file which creates the session, login “pages”
$app->get('/session', function() ...
$app->post('/login', function() use ($app) { ...
dbConnect, passwordhash files…Everything is the same exact folder and file structure as the tutorial. I just can’t seem to get this going…
Could it have anything to do with my wordpress website / server related? If I go to http://mywebsite.com/myproject/api/vi/login it comes up with my regular websites page not found - and if i go to http://mywebsite.com/myproject/api it comes up with the index file structure, where I have noticed the v1 folder is missing…
aeres, you said you are working on an app that communicates with API, is this API your own hosted one or a remote public API?
If this is your own API, you need to make sure your htaccess files are setup correctly, you have the correct file permissions enabled and can access it within the browser outside your application.
Doesn’t look like you’ve got those steps complete yet.
in your backend because basically, while cors with ajax is not a problem in general, with a wildcard it is at least i had several issues with it and instead of using htaccess with * wildcard, i did this.
what do your developer tools say when trying to connect with your api? any console.log outputs, any network related issues which maybe lead to the core problem?
I got my htaccess working last night, but I removed the wildcard and switched to your code anyway, it’s working (no CORS issues anymore)
However still getting the 404 errors…Regarding the wordpress plugin, not sure if I need that. My main website, mywebsite.com is a wordpress website, but I have subfolders created for other projects, and one of them is myproject/api - does having wordpress installed on the base domain have any influence as to why this isnt working?
I am using index.html in my www folder, as this will be the basis of the app (APK)
Not sure if you can have a php file in the app?
Thankyou all for helping me through this so quickly!
I appreciate you are stuck on this, but this isn’t an Ionic issue, so it’s not suitable for this forum. You should post your API problem on Stack Overflow and seek assistance there.
Alternatively move this topic out of the Ionic category and into uncategorised, you should also provide all of the code related to the 404 resource. Currently it’s difficult for anyone to help you if you don’t provide the web service code. Bare in mind what I’ve said about it not being Ionic related (yet) as it’s a 404 error you are receiving.
Finally figured it out! My htaccess has the rewritebase, which is like this: /myproject/api/v1/
and so the proxy setup in ionic.project had to match (above I had just “/v1”)
Celebrated too soon! To make it work on the phone as well as the browser (localhost) I need to change ServiceBase = 'http://mywebsite.com/myproject/api/v1/';