Using grocery crud with fetch

Hi, this question might be stupid, but i did not find any solution,

Is it possible to use gc with fetch ? Something like…

fetch(myRequest)
.then((response) => { … }

KR,
Marc

Hello @MarcVdB ,

Your question is not stupid at all! Integrating Grocery CRUD Enterprise with fetch is indeed possible. On the other hand Grocery CRUD Enterprise is a PHP library that helps you create a CRUD interface quickly, so I don’t see the point of doing that :thinking:. To interact with it using JavaScript’s fetch API, you need to understand the endpoints that GCE provides for data operations (like create, read, update, delete) and use fetch to make requests to these endpoints. But you shouldn’t have any issues with that since everything is an API request for Grocery CRUD.

Important Points:

  • URL: Ensure the URL in the fetch call points to the correct PHP file handling your CRUD operations.
  • CORS: If your frontend and backend are on different domains, make sure to handle CORS appropriately.

Hello Johnny,
i have a page with a decent amount of static content and a div that shows one of a few different (little ) tables (1-20) rows. The user can chose a table with a select and i wan’t to fetch the gc grid without reloading the rest of the page.

If you say it is doable, i’ll dive a bit deeper into it.

Thanks and KR,
Marc

Ok, i don’t get it.
My approach is to try to run the states “Main” and “Initialize” once. And then fetch the data of the state “datagrid” (with a different $gccrud->settable per fetch) to display it in the div.

However i fear that i don’t understand the inner working of gc enough, because all i try to do always results in the "Ooooops, something went wrong! " message :confused:

Any hint how to do it correctly would be greatly appreciated
tia,
Marc

Hello @MarcVdB and sorry if I was misunderstood. You can use the fetch function in JavaScript to just fetch the data but not the entire CRUD since this is build with JavaScript. You can find the source code here: User's Page Login (this is frontend source code).

So for example you can fetch this URL: https://demo-v3.grocerycrud.com/getting-started?action=initial which will really return you a JSON output (you can click on it to see what I mean) but that’s all really. I will try in the future to add some architecture so people can also understand what it happens in the background.

Regards
Johnny

1 Like