Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
161 views
in Technique[技术] by (71.8m points)

javascript - POST/Redirect throws a `Connection was reset` browser error

I'm building a one-page checkout for a customer of ours. This checkout is supposed to contain all forms for credentials, shipment and payment. Editing previously entered values should also be possible. This is all going fine except for one thing.

My page is built of multiple includes:

  • credentials
  • shipment
  • payment

In each of these includes I check if the concerning data is in the session and if it is I show a different view. Nothing special here.

For example:

<?php
if (is_array($_SESSION['credentials'])) {
    ... show filled in values ...
} else {
    ... show form ...
}
?>

When values are already set, I also show an edit button. I do this as follows:

<div class="left-column">
    <h1 class="title-left">Step 1 - Credentials</h1>
    <div class="pull-left" style="width: 50%;">
        Name: name<br />
        Address: Address 11<br />
        Postal Code: 12345AA<br />
        Country: Country<br />
    </div>

    <br />
    <div style="clear: both;height: 10px;"></div>
    <center>
        <form method="POST" action="/checkout/credentials/">
            <input type="hidden" name="edit" value="credentials">
            <button class="sexybutton sexysimple sexybestel">Edit</button>
        </form>
    </center>
</div>

Followed by:

<div class="left-column">
    <h1 class="title-left">Step 2 - Shipment</h1>
    <i>Select a shipment method</i>
    <form method="POST" action="/checkout/payment/">
        <input type="radio" value="0" name="shipmentmethod"> Collect<br />
        <input type="radio" value="1" name="shipmentmethod"> Deliver<br />
       <input type="submit" value="Go to Step 3" class="sexybutton sexysimple sexybestel pull-right" name="shipment">
    </form>
</div>

In the credentials include I check for the $_POST['edit']. If it is set, i will show the form again with the customer's previously filled in data in the input fields.

The problem

Whenever I click the edit button the first time, it throws me a Connection was reset browser error. If I refresh the page, it will ask for me to submit the form again. When I do this the error is gone. I can't seem to figure out where this is coming from. I checked the server logs but there is nothing unusual there.

*Note: * The same problem occurs between the shipment and payment steps.

Relevant htaccess

Options       +FollowSymLinks
RewriteEngine On
RewriteBase /

order allow,deny
allow from all
RewriteCond %{HTTP_HOST} ^tapijttegelhandel.nl
RewriteRule ^(.*)$ http://www.tapijttegelhandel.nl/$1 [R=permanent,L]
AddDefaultCharset utf-8

RewriteRule ^checkout/               /index.php?mod=checkout&action=show [NC,L,QSA]

index.php

case 'checkout':
    $action = isset($_GET['action']) ? $_GET['action'] : '';
    switch ($action) {
        case 'completed':
            # ...
            break;

        case 'cancelled':
            # ...
            break;

        case 'credentials':
        case 'shipment':
        case 'payment':
        case 'edit':
        default:
            include $_SERVER['DOCUMENT_ROOT'].'checkout/show.php';
            break;
    }
    break;

Progress

  • I've dumped the session variable to see if there was something strange in the session. (Nothing strange here)
  • I've installed a Tamper Data plugin for firefox to check the POST data. (Nothing strange here either)

Update

I found something in my code I skipped when checking everything last time. This could however have something to do with my problem.

<script type="text/javascript">    
         window.history.forward();
         function noBack() { 
              window.history.forward(); 
         }
    </script>
</head>
<body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">

Workflow

/cart GET 200 OK
/checkout/credentials/ GET 304 OK
/checkout/credentials/ POST 304 OK
# edit
/checkout/credentials/ POST - Error 'Connection was reset'
# Refresh
/checkout/credentials/ POST 200 OK
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

"Connection was reset"

Can sometimes mean a php crash. Without seeing the exact files it's hard to guess if and why this is happening.

Make sure to check the error_log, type: php --info | grep error to see what file it's being logged to (if you are on linux/unix).

My guess is a stray break; statement somewhere see this answer for a possible cause: https://stackoverflow.com/a/20036720/988324

You would find some trace of this in your error logs though. If you can provide this I might be able to help more.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...