Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery post request interrupted: Only half of post parameters arrive
    primarykey
    data
    text
    <p>I have a noticed a strange phenomenon in my LAMP environment.<br> Over the frontend I execute an AJAX post request with jQuery like this:</p> <pre><code>$.post('save.php', {data1: d1, data2: d2, [...], dataN: dN}) </code></pre> <p>The variables <code>d1</code> to <code>dN</code> are collected from the website (e.g. from text inputs, textareas, checkboxes, etc.) with jQuery beforehand.</p> <p>The file <code>save.php</code> takes the post parameters <code>data1</code> to <code>dataN</code> and saves them in the database in one query.</p> <p>The request takes about 500ms and works without problems <em>unless</em> I change pages (e.g. by clicking a link) during the request.</p> <p>Normally, I would expect the request to be aborted and ignored (which would be fine) <em>but</em> (and this is the strange behaviour) the request seems to be completed but only with part of the data transmitted and thus saved.</p> <p>That means for example, that the php script saves only <code>data1</code> to <code>data5</code> and sets <code>data6</code> to <code>dataN</code> to empty.<br> The problem seems to be caused by the AJAX request already (not the php script) since fields <code>$_POST['data6']</code> to <code>$_POST['dataN']</code> are not set in php in this scenario.</p> <p>So my questions:<br> <em>Why does this happen (is this expected behaviour)?</em><br> <em>How can I avoid it?</em></p> <p><strong>Update</strong><br> The problem is neither jQuery nor php solely. jQuery collects the values correctly and tries to post them to php. I just validated it - it works. The php script on the other hand handles everything it gets as expected - it just does not receive the whole request.<br> So the problem must be the interrupted request itself. Unlike I'd expect it does not abort or fail, it still transmits all the data until the cut off.<br> Then php gets this post data and starts handling it - obviously missing some information.</p> <p><strong>Update 2</strong><br> I fixed the problem by adding a parameter <code>eof</code> after <code>dataN</code> and checking if it was set in php. This way I can be sure the whole request was transmitted.<br> Nevertheless this does not fix the source of the problem which I still don't understand.<br> <em>Any help anyone?</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload