1

Updated the question in order to make it more clear:

I'm interacting with an API in order to do some CRUD operations.

Now should I call the API directly in my JQuery/Javascript code, and wrap the POST requests into actions server side? Or should I simply throw both GET and POST requests to the API into the server side, and then call the actions at server side?

0

1 Answer 1

1

Your question is a little unclear, but it sounds like you are running in to a cross-site-scripting issue. You can not issue ANY ajax request via javascript to a domain other than the one the current page came from. jQuery supports every HTTP method including post, but if you try to issue a request to a different domain, the browser will disallow the request. There are workarounds for this, such as JSONP.

Please clarify your original question if this is not the issue.

Sign up to request clarification or add additional context in comments.

6 Comments

Is the API hosted on your server (same domain name), or somewhere else?
It's hosted somewhere else. I'm aware of that I cant do POST requests to it from my jquery code due to security issue(s). Therefore I'm planning to place those POST requests in the logic, in my app instead. Now I'm wondering whether it would make sense to place the GET requests there too.
Yes it would. It makes more sense to have all your interactions with the API in one place.
I know this is a little more abstract... But what if I've two APIs? One thats running on same domain, and another thats not? Would it make sense to place the first client side, and the second server side, or would it make more sense to place both server side?
It you have one running on the same domain, I would interact with it client side unless the two API's logic are tied together. I find using an ajax request is almost always easier than the same thing server side.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.