0

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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by ShawnCplus
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.