如何转换简单的形式提交给Ajax调用; [英] How to convert simple form submit to ajax call;

查看:125
本文介绍了如何转换简单的形式提交给Ajax调用;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个输入域的表单可以像

I have a form with input field which can be accessed like

var algorithm = document.forms["algoForm"]["algorithm"].value;
var input = document.forms["algoForm"]["input"].value;

和早期的呼叫

and earlier call was

document.forms["algoForm"].submit();

和形式

<form name="algoForm" method="post" action="run.do">

这一切都运行得很好
现在我想将它转换为Ajax调用,这样我可以使用在同一页上从Java code返回的数据。所以我用soemthing像

It all run fine
Now I wanted convert it to the ajax call so that I can use the returned data from java code on the same page. So I used soemthing like

        var algorithm = document.forms["algoForm"]["algorithm"].value;
        var input = document.forms["algoForm"]["input"].value;
        var data = 'algorithm = ' + algorithm + '&input = ' + input;


    $.ajax(
            {
                url: "run.do",
                type: "POST",
                data: data,
                success: onSuccess(tableData) 
        //line 75       {
                    alert(tableData);
                }

            }
        );

不过上述code不运行。请帮我使其运行

However the above code doesn't run. Please help me make it run

推荐答案

我不知道如何,但是这一个运行良好,

I don't know how but this one runs well,

    var algorithm = document.forms["algoForm"]["algorithm"].value;
    var input = document.forms["algoForm"]["input"].value;



        $.post('run.do', {  
        algorithm  : algorithm,
        input    : input
        }, function(data) {                  
        alert(data)
    });

这篇关于如何转换简单的形式提交给Ajax调用;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆