Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If jQuery AJAX data is sent/received, is it possible to only receive SOME of the data?

Let's assume this is being executed in jQuery:

$.ajax({
    url : 'ajaxcall.php',
    data : { 'data' : { ary : [1,2,3,3,4,5], txt : "ima let u finish" } },
    dataType : 'json',
    type : 'post',
    timeout : 10000
});

And ajaxcall.php contains:

$return_obj = array();
$return_obj['ary'] = array(9,8,7,6,5);
$return_obj['txt'] = "ok then";

echo json_encode($return_obj);
die();

I'm expecting the following situations to occur (due to packet loss, connection problems, etc):

  • Ajaxcall.php executes, but the $_POST variable is empty.
  • The promises of the $.ajax() call are executed, but the data returned to them is empty.

However, what I'm really worried about are situations like these:

  • Ajaxcall.php executes and $_POST['data']['txt'] has expected values but $_POST['data']['ary'] is missing some values.
  • The promises of the $.ajax() call are executed and data.ary has the expected values, but data.txt is only half a string (e.g., "ok t").

Are these situations possible?

like image 925
EleventyOne Avatar asked Jul 18 '13 20:07

EleventyOne


1 Answers

In short: no, that's not possible. HTTP is based on TCP which guarantees delivery of data. Both the server and client would be aware of an issue that would cause some data to be missed. The TCP layer would retransmit the data as needed until it is complete.

Packet loss and out of order delivery are not uncommon the internet since there is no rule that says routers must forward all packets but TCP automatically corrects for those issues.

like image 84
G-Nugget Avatar answered Sep 30 '22 00:09

G-Nugget