You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用JQuery提交表单时POST后立即发起GET请求的问题求助

POST请求后立即出现GET请求的问题排查与解决

Hey there, let's break down this weird issue where your dynamic form submission is triggering a POST followed right by a GET request. I've worked with similar stack setups before, so here's what to check and fix:

First, Identify the Root Cause

The most common reason for this sequence is a server-side redirect. When your browser sends a POST and gets a 3xx (redirect) response back, it automatically fires a GET to the redirect target. Let's verify this first:

  • Open your browser's DevTools (F12) → go to the Network tab.
  • Watch the requests when the page loads. Check the status code of your initial POST request. If it's 301/302/307, that's the culprit.

1. Fix Spring Controller Redirect Behavior

Since your backend uses Spring 2.5, check the Controller method handling the POST request:

  • If the method returns something like new ModelAndView("redirect:/some-path") or uses the redirect: prefix, that's causing the browser to follow with a GET.
    • If you don't need a redirect: Update the method to return the intended view directly (without redirect:) or return a JSON response if it's an API endpoint.
    • If you do need to redirect but want to avoid the GET: Consider using a POST redirect pattern (though this is less common) or switch to an AJAX POST instead of form submission (more on that below).

2. Check Apache Proxy Configuration

Your Apache load balancer might be modifying requests or sending redirects unexpectedly:

  • Look for RewriteRule or ProxyPass directives in your Apache config that could be altering POST requests.
  • Check Apache's access.log and error.log to see if the proxy layer is initiating any redirects before the request reaches WebLogic.

3. Optimize Your Frontend Code

Your current form submission code works, but there are small tweaks to avoid potential edge cases, plus a better alternative if page navigation isn't required:

Tweak the Dynamic Form Code

function navigateWithForm() {
    // Clean up syntax for readability
    var form = $('<form>', {
        method: 'POST',
        action: url
    });
    form.append(getInput());
    form.appendTo('body').submit();
    form.remove(); // Remove the form after submission to avoid duplicates
}

function getInput() {
    return $('<input>', {
        type: 'hidden',
        name: 'header',
        value: '<%=emailID%>'
    });
}

Also, your jQuery version (1.4) is extremely outdated—upgrade to a modern stable version (like 3.x) to avoid unpatched bugs.

Switch to AJAX POST (No Page Redirect)

If you don't need to navigate to a new page after the POST, using AJAX gives you full control and eliminates automatic redirects:

$(document).ready(function() {
    $.ajax({
        url: url,
        method: 'POST',
        data: {
            header: '<%=emailID%>'
        },
        success: function(response) {
            // Handle successful response here
            console.log('Request succeeded:', response);
        },
        error: function(xhr, status, error) {
            // Handle errors
            console.error('Request failed:', error);
        }
    });
});

Final Troubleshooting Steps

  1. Confirm the POST response status code via DevTools.
  2. Audit your Spring Controller's return logic for unintended redirects.
  3. Verify Apache proxy config isn't modifying requests.
  4. Test with updated jQuery or AJAX to rule out frontend quirks.

内容的提问来源于stack exchange,提问作者ramesh027

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:20:31