Hi,

I am new to ajax and was taking look at code snippets.

Most of the code open and send are like this:

var client = new XMLHttpRequest();
 client.open("POST", "/log");
 client.send(message);

They open a connection and send the msg. Isnt connection open a costly call since the connection is set up over TCP/IP for HTTP? Why do we need to do a open each time? Wont the send go fine with the previous send session connection?

Bharath

Hi,

I am new to ajax and was taking look at code snippets.

Most of the code open and send are like this:

var client = new XMLHttpRequest();
 client.open("POST", "/log");
 client.send(message);

They open a connection and send the msg. Isnt connection open a costly call since the connection is set up over TCP/IP for HTTP? Why do we need to do a open each time? Wont the send go fine with the previous send session connection?

Bharath

If you use a Connection: keep-alive header then the browser would never know when the AJAX call is finished and you've never get data back. AJAX calls are fairly inexpensive unless you're sending insane amounts of data.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.