0

我以这种方式在文本字段的 onSubmit 事件上调用 javascript 函数:

  <form action="#" onsubmit="getTestResults()">
        <input class="button2" type="text" name="barcode" >
   </form> 

和javascript函数是:

function getTestResults(){

        $.ajax({
            type: "Post",
            url : "uploadTestResult.htm",
            success : function(response) {
                alert(response);
                $("#testResultCount0").html(response);
            }
        });
    }

但我收到错误:HTTP 状态 405 - 不支持请求方法 'GET' 我使用类型作为帖子。我不想提交整个表格。这是正确的方式还是他们的任何替代方式?请建议

4

2 回答 2

0

尝试在函数return false;末尾添加 a 。getTestResults

于 2013-11-12T13:33:13.817 回答
0

这样做是为了使用 AJAX 提交表单并使用 POST 发送数据

<form id="uploadForm" action="#" onsubmit="getTestResults()">
     <input class="button2" type="text" name="barcode" >
</form>

function getTestResults(){

    $.ajax({
        type: "POST",
        url : "uploadTestResult.htm",
        data: $("#uploadForm").serialize(),
        success : function(response) {
            alert(response);
            $("#testResultCount0").html(response);
        }
    });
    return false;
}
于 2013-11-12T13:41:14.050 回答