weixin_33713503 2017-02-18 21:16 采纳率: 0%
浏览 40


trying to understand all this about AJAX, first of all I wanted to know how to refresh a page and keep my position on the page, which was possible, however, that was not the case on form post, that just jumped me right back to the top.

So after searching around on how to solve that, posting with AJAX seems to be my solution, I just can't seem to get all of it.

<form method="post" action="~/getAJAX.cshtml" id="ajaxform">
        <input type="text" name="kg" id="kg"  />
        <input type="submit" />
<script type="text/javascript">
    $(function () {
        $('#ajaxform').submit(function (event) {
            event.preventDefault(); // Prevent the form from submitting via the browser
            var form = $(this);
                type: form.attr('method'),
                url: form.attr('action'),
                data: form.serialize()
            }).done(function (data) {
                // Optionally alert the user of success here...
            }).fail(function (data) {
                // Optionally alert the user of an error here...

This is the code I have so far. The thing I do not understand is what exactly should be on my "action" page?

At the moment I put this on my action page.

var db = Database.Open("Database");

var getKG = Request.Form["kg"];

var query = "SELECT * FROM Test WHERE kg = @0";
db.Execute(query, getKG);

This is just a test, I don't really know what to expect or anything, I would like to show the results on the page I post from, any guiding for this please?

Note that this is not a MVC project, therefore my problems with finding any good solutions or help, it's just normal CSHTML files.

  • 写回答

0条回答 默认 最新



      • ¥15 PMM 9010/30P
      • ¥15 pom文件依赖管理,未找到依赖
      • ¥15 现在后端返回给我一堆下载地址,都是一个视频切片后的,如何在uniapp安卓环境下将这些分片的视频下周并且合并成原始视频并下载到本地。
      • ¥15 Unity导出2D项目运行时图片变成马赛克
      • ¥15 关于communitytoolkit.mvvm的生成器得到的代码看起来没有被使用的问题
      • ¥15 matlab中此类型的变量不支持使用点进行索引
      • ¥15 咨询第六届工业互联网数据创新大赛原始数据
      • ¥15 Pycharm无法自动补全,识别第三方库函数接收的参数!
      • ¥15 STM32U575 pwm和DMA输出的波形少一段
      • ¥30 android百度地图SDK海量点显示标题