Jquery Javascript Ajax Post数据
Javascript:Jquery Javascript Ajax Post数据,jquery,asp.net-mvc,http-post,Jquery,Asp.net Mvc,Http Post,Javascript: function LoginButton1OnClick() { $.ajax({ type: "POST", url: "Login/MainPageRegister", cache:false, data: { LoginEmailText: $("#LoginEmailText
function LoginButton1OnClick() {
$.ajax({
type: "POST",
url: "Login/MainPageRegister",
cache:false,
data:
{
LoginEmailText: $("#LoginEmailText").val(),
LoginPasswordText: $("#LoginPasswordText").val(),
},
success: function (mydata) {
$("#BodyPage").html(mydata);
}
});
}
[HttpPost]
public ActionResult MainPageRegister(MyModel model)
{
return View();
}
操作结果:
function LoginButton1OnClick() {
$.ajax({
type: "POST",
url: "Login/MainPageRegister",
cache:false,
data:
{
LoginEmailText: $("#LoginEmailText").val(),
LoginPasswordText: $("#LoginPasswordText").val(),
},
success: function (mydata) {
$("#BodyPage").html(mydata);
}
});
}
[HttpPost]
public ActionResult MainPageRegister(MyModel model)
{
return View();
}
我将数据发布到“MainPageRegister”。但是出现了两个问题
任何帮助都将不胜感激。问题在于您正在执行ajax请求,ajax请求不会修改浏览器历史记录,因此您无法返回 您可以使用HTML5 pushState()通过JS以及hashtags修改历史记录。在JS中,可以使用window.location.hash修改URL标签 这个问题的第一个答案可以让这个问题更加清晰:
哈希url的快速示例
var storedHash = window.location.hash; //get hash
if (storedHash !== '') { //if no empty
hashChanged(storedHash);
}
window.setInterval(function () {
if (window.location.hash != storedHash) { //chek if curent hash not == to stored hash when page was opened
storedHash = window.location.hash;
hashChanged(storedHash); //if change call a funcin
}
}, 100); //check hash if changed
function hashChanged(storedHash) {
var link = storedHash.substr(1, storedHash.length); //get the link
$.ajax({
type: "POST",
url: link+".php", //in browser url should look like #profile so when somebody
cache:false,
data:
{
LoginEmailText: $("#LoginEmailText").val(),
LoginPasswordText: $("#LoginPasswordText").val(),
},
success: function (mydata) {
$("#BodyPage").html(mydata);
}
});
}
如果您想使用ajax发布数据,并且希望支持url,则需要围绕这个概念设计应用程序 我建议大家看看emberjs或sammyjs。这些都是围绕url状态概念构建应用程序的好框架
你能不能让你的表单代码??1-Url永远不会在浏览器中更改。在我发布数据之后。答:这是ajax要求。我想使用javascript或ajax等来发布数据。你有什么建议吗@PilotUse哈希标记url domain.com/#url@user3239568对于asyc操作,请使用
AJAX
什么是解决方案?我想使用ajax/javascript发布数据。你有什么建议吗?并非所有浏览器都支持HTML5((我编辑了响应,您可以使用HTML5 pushState以及哈希标记。在JS中,您可以使用window.location.hash
修改URL哈希标记。@gpopoteur如果我使用window.location.hash,URL更改可以。但是我不能返回和转发页面。您有返回和转发的解决方案吗?@user3239568我相信使用window.locat时会这样做。)ion.hash您可以在历史记录中前后移动,您使用的浏览器和浏览器版本是什么?如果我可以更改url,如何在浏览器中前后移动?有什么方法可以解决此问题吗?单击链接…Html 5或JS感谢您对Froxz的所有帮助。但我需要您根据我的示例代码编写代码。您可以请将您的代码应用到我的问题代码?因为我尝试了您的代码,但是,我不能同时更改url和post数据。