skip to Main Content

I have a problem with my API. here’s the situation :

  • I have API created with laravel
  • I want to fetch the data from index.html with jQuery
  • I have hosting the API for the server (laravel), in free hosting infinityfree.
  • for the index.html it still on my localhost. Because the idea is I’m using Cordova Apache for the view and will converted into apk later.
  • when I’m in the localhost an run the laravel server (with PHP artisan serve), it works perfectly fine, but when I hosted it, I cant get the data
  • the weird part is that, my status for the request is 200, but I received an error. But when I click the endpoint using dev tool -> browser, the data shows
  • enter image description here

I don’t know what the cause of the problem, since in my localhost is just fine. can anyone help me?

EDIT:

  • here’s the response when I try with postman
    enter image description here
  • again, in localhost, it shows the data, not this

EDIT :

  • all my return request is like this :
return response()->json([
     'status' => true
], 200);
  • and the jQuery ajax like this :
$.ajax({
    type: "get",
    url: GLOBAL_URL + "endpointapi",
    dataType: "json",
    xhrFields: {
        withCredentials: true
    },
success : function(){},
etc...

mm…. anyone?

EDIT:
Is hosting service provider matter? I mean since I’m using free hosting, I’m afraid that is limited and can’t use for API purpose. If so, anyone know a free hosting and can use for API purpose?

2

Answers


  1. Chosen as BEST ANSWER

    Ok everyone, I think I have the answer. simple... It's because infinity free hosting cannot use for API purposes (for free version, IDK for the paid version). You can search it why it cannot support for API purposes.

    I change my hosting to paid hosting (of course not in infinityfree app), and then it works just fine.


  2. Sounds to me like you are facing a CORs issue where you are trying to fetch data from your InfinityFree hosted API from your localhost.

    CORS means Cross-Origin Resource Sharing and for the most part laravel is equipped to properly deal with it. You might just need to configure config/cors.php paths key.

    Laravel Documentation on CORS

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search