You are viewing our Forum Archives. To view or take place in current topics click here.
AJAX vs cURL : Which is better?
Posted:
AJAX vs cURL : Which is better?Posted:
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
I was having a discussion with some other students about two ways to code the following, which do you think would be a better approach?
Scenario
You are a user on Server-X using Website-X.
You want to query a database on Server-Y which has a web service performing an INSERT SQL statement.
Version 1: AJAX Request
Create an AJAX function to access the web service, send the parameters via POST using XHR.
Handle the response of the web service in the AJAX callback (e.g. it will return a HTTP status code).
Output an appropriate response to the webpage to confirm the insert was successful.
Version 2: cURL Request
Create an AJAX function to send the parameters via POST to the local server (Server-X).
Send the data via POST using cURL to Server-Y.
Handle the response of Server-Y in the php script of Server-X
Output a user-friendly response to the front-end confirming a successful input.
The my friend made about using a cURL request was that it offloads the response handling to the local server ensuring the web page is faster.
My point, for just using AJAX, is that it doesn't matter about the response handling considering it's only a simple switch statement. You are then cutting out the middleman (Server-X) and should receive a faster response overall.
Is there a 'correct' way to do this?
Scenario
You are a user on Server-X using Website-X.
You want to query a database on Server-Y which has a web service performing an INSERT SQL statement.
Version 1: AJAX Request
Create an AJAX function to access the web service, send the parameters via POST using XHR.
Handle the response of the web service in the AJAX callback (e.g. it will return a HTTP status code).
Output an appropriate response to the webpage to confirm the insert was successful.
Version 2: cURL Request
Create an AJAX function to send the parameters via POST to the local server (Server-X).
Send the data via POST using cURL to Server-Y.
Handle the response of Server-Y in the php script of Server-X
Output a user-friendly response to the front-end confirming a successful input.
The my friend made about using a cURL request was that it offloads the response handling to the local server ensuring the web page is faster.
My point, for just using AJAX, is that it doesn't matter about the response handling considering it's only a simple switch statement. You are then cutting out the middleman (Server-X) and should receive a faster response overall.
Is there a 'correct' way to do this?
#2. Posted:
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Using cURL as you're describing it in version 2 is pretty pointless.
If there was a need to verify the data being sent/received, obviously passing it through your server would make sense.
It would be more secure, sure, but if the only thing you're doing with the data is notifying them of the response, there's not really any need for additional checks. Your server is just acting as an unnecessary relay at that point.
If there was a need to verify the data being sent/received, obviously passing it through your server would make sense.
It would be more secure, sure, but if the only thing you're doing with the data is notifying them of the response, there's not really any need for additional checks. Your server is just acting as an unnecessary relay at that point.
- 1useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
For a particular task, we have users registering and logging in to the website.
The web service needs to take a username as part of the insert statement.
Would you recommend using curl so that the local server can verify the user before sending the post request?
The way I planned on implementing it was to just send the currently logged in user's username in the ajax post request. (being that if the username was empty, the web service would just return a suitable http error code.
The web service needs to take a username as part of the insert statement.
Would you recommend using curl so that the local server can verify the user before sending the post request?
The way I planned on implementing it was to just send the currently logged in user's username in the ajax post request. (being that if the username was empty, the web service would just return a suitable http error code.
- 0useful
- 0not useful
#4. Posted:
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
For something like that, the "proper" thing to do would be to check the name on your end, that way you could give detailed feedback about what's wrong with the name if something doesn't match up.
Still, something that can be handled client side.
Still, something that can be handled client side.
- 1useful
- 0not useful
#5. Posted:
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
-Deano wrote
The web service needs to take a username as part of the insert statement.
don't u know how to use sessions?????
- 0useful
- 0not useful
#6. Posted:
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
lamronsavage wrote-Deano wrote
The web service needs to take a username as part of the insert statement.
don't u know how to use sessions?????
I am pretty much a novice with php but I don't see what session variables has to do with updating a database...
- 0useful
- 0not useful
#7. Posted:
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
-Deano wrotelamronsavage wrote-Deano wrote
The web service needs to take a username as part of the insert statement.
don't u know how to use sessions?????
I am pretty much a novice with php but I don't see what session variables has to do with updating a database...
i read this as u wanna insert based off of an authd user with the client sending u their username an if u did it that way without a session they could jus modify it
also y would u send a request to ur server to send a request
- 0useful
- 0not useful
#8. Posted:
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
The point was that sending via ajax would not have any verification which is the scenario where curl would be necessary.
The general question was is there a benefit to sending an ajax request to the server before sending it to the web service. Speed answered this confirming my thoughts.
The general question was is there a benefit to sending an ajax request to the server before sending it to the web service. Speed answered this confirming my thoughts.
- 0useful
- 0not useful
#9. Posted:
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
Status: Offline
Joined: Feb 25, 20168Year Member
Posts: 19
Reputation Power: 13
-Deano wrote The point was that sending via ajax would not have any verification which is the scenario where curl would be necessary.
The general question was is there a benefit to sending an ajax request to the server before sending it to the web service. Speed answered this confirming my thoughts.
what u said u trynna do made absolutely no sense at all in the first place
sending a ajax request to send a request with cURL is not gonna make anything faster - less requests in the chain the better
secondly tf do u mean 'verification' csrf tokens exist for a reason an if u mean to verify a user again session data......
- 0useful
- 0not useful
#10. Posted:
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
Status: Offline
Joined: Aug 19, 201014Year Member
Posts: 5,243
Reputation Power: 532
The original topic was asking if there was any use to use ajax and curl together due to a discussion with a few classmates. I didn't say it was sensible to do so...
The 'validate a username' was just an example. This is not a functional bit of work I am doing.
The 'validate a username' was just an example. This is not a functional bit of work I am doing.
- 0useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.