1
ファイルコントローラークラスのthemessという関数があり、JQuery AJAX経由で情報を返送しようとしていますが、コントローラーのイベントはデバッグ時に発生しません。ASP.NET MVC JQuery Ajax関数が起動しない
URLですが、受信したコードを処理することになっhttp://localhost:8081/character/two
機能である: -
public ActionResult themess(string sText)
{
return Json(new { success = true, message = "Inserted" }, JsonRequestBehavior.AllowGet);
}
コードはポストを受けているようだ、それはに行くしているようです間違った機能。 [httpPost]機能に移動します。
私はバイオリンを経由してトレースするとき、私はthemessが発射されていない理由として何をしないのです
POST http://localhost:58281/character/two/themess HTTP/1.1
Host: localhost:58281
Connection: keep-alive
Content-Length: 13
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://localhost:58281
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Content-Type: application/json; charset=UTF-8
Referer: http://localhost:58281/character/two
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Cookie: ASP.NET_SessionId=3vhn5okbsiblowtkt34puxsf;_ga=GA1.1.513197781.1472146597; __atuvc=257%7C34%2C174%7C35%2C699%7C36%2C145%7C37; __atuvs=57dae9e7623c17f3002
STEXT =メッセージ(この行は、上記のトレースに接続されている)
を取得し、私はRouteConfigに何かを置くことになっています。
routes.MapRoute("CharacterRule", "character/{id}/{Misc}", new { Controller = "file", action = "Index", id = UrlParameter.Optional });
routes.MapRoute("CharacterDupRule", "character/{id}", new { Controller = "file", action = "Index", id = UrlParameter.Optional });
これは私のjQueryの機能の提案を事前に
$("#form1").submit(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: '@("/file/two/themess")',
dataType: "json",
data: 'sText=Message',
contentType: "application/json; charset=utf-8",
success: function() {
alert('success');
},
failure: function(response) {
alert(response.d);
}
});
});
おかげです。
ajax呼び出しであなたのURLに '/ character/two/themes'を使用しますか? http:// localhost:8081/character/two ** – Zack
これは理想的でしょう。なぜなら、/ file/twoを置く理由は、@Urlをどこかで使用しようと読んだからです.Action( "postcomment")とそれが大まかに翻訳されたもので、URL.Actionまたは/ character/two/themessを使用する必要があります、私は修正し、テストし、更新します。 – MiscellaneousUser
渡すデータはjson形式ではありませんが、そのように宣言しています。 –