Jquery $.post创建新表单

Jquery $.post创建新表单,jquery,http-post,Jquery,Http Post,我想让用户能够创建一个新的游戏。这是我到目前为止所拥有的。我对$有问题。post。我该怎么做 这是我的索引: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <form name="Name Of Gam

我想让用户能够创建一个新的游戏。这是我到目前为止所拥有的。我对
$有问题。post
。我该怎么做

这是我的索引:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>

    <body>
        <form name="Name Of Game" action=$.post("data/games/create",  {title:""},function(data){});  method="get">
            New Game: <input type="text" name="game">
            <input type="submit" value="Create">
        </form>
    </body>
</html>

新游戏:
这是我的控制器:

using PlanningPoker.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace PlanningPoker.Controllers
{
    public class GMController : ApiController
    {
        private static List<Game> games = new List<Game>() {
                new Game() {
                    ID = Guid.NewGuid(),
                    Title = "D&D"
                }
            };

        [Route("data/games")]
        public IEnumerable<Game> GetAllGames() {
            return games;
        }

        [Route("data/games/create")]
        public Guid CreateGame(string title) {
            Game g = new Game() {
                ID = Guid.NewGuid(),
                Title = title
            };

            games.Add(g);

            return g.ID;
        }
    }
}
使用PlanningPoker.Models;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
Net系统;
使用System.Net.Http;
使用System.Web.Http;
名称空间规划Poker.Controllers
{
公共类控制器:ApiController
{
私有静态列表游戏=新列表(){
新游戏(){
ID=Guid.NewGuid(),
Title=“D&D”
}
};
[路线(“数据/游戏”)]
公共IEnumerable GetAllGames(){
返回游戏;
}
[路线(“数据/游戏/创建”)]
公共Guid CreateGame(字符串标题){
游戏g=新游戏(){
ID=Guid.NewGuid(),
头衔
};
游戏。添加(g);
返回g.ID;
}
}
}

您应该为表单的提交放置一个eventListener

$('form').on('submit', function (){
      //TODO: put params in variable here

      $.post("data/games/create",  params,function(data){})
});