PDA

View Full Version : AJAX-mysql-multiple queries


zto
05-14-2009, 08:09 PM
greetings,

i'm quite new in javascript programming and just started feeling more comfrotable with AJAX

I have a question for you

i have a page in which:
- i get data from mysql and present them on screen
- I insert data in mysql
- delete data from mysql

my question is which is the best way to implement those operation useing ajax and php

should i have 3 completely different ajax functions? should i have one and change only the .php i send data to?
or should i have one function and pass all the data with the appropriate flags to one .php file which will choose which function to use?

i hope you understand what i mean
sorry for my bad english

thnx
giorgos

bdl
05-15-2009, 03:41 AM
Generally speaking, you should use GET requests to retrieve data from the server, and POST requests to send data to the server. Based on that general rule, I'd probably create an object with three methods, all using the same XMLHttpRequest object to perform different tasks, maybe a generic GET method that can be altered based on what's passed to it (either a record ID value to delete, or null). Whether or not you use multiple PHP scripts to handle each request is up to you.

zto
05-15-2009, 10:33 AM
Generally speaking, you should use GET requests to retrieve data from the server, and POST requests to send data to the server.

why that? are there security problems when using GET to retrieve and send data to the server?

bdl
05-15-2009, 08:43 PM
why that? are there security problems when using GET to retrieve and send data to the server?

Not really anymore than a POST request. It's just logical; an HTTP GET request is "getting" data from the server. You're not changing anything. An HTTP POST request is "posting" data to the server, so you're actually modifying something on the server, e.g. inserting or updating a database record. Aside from that, a GET request sends data right over the URI, and you probably don't want that when performing an insert or update. Since this is the case, technically it's not as secure as using POST, because all the server logs will contain any data you're inserting; not a huge deal, but for security conscious individuals it may matter.

Google search : HTTP POST vs GET (http://www.google.com/search?&q=HTTP%20POST%20vs%20GET)
Methos GET and POST (http://www.cs.tut.fi/~jkorpela/forms/methods.html)