单击任何按钮时,页面URL中的参数都会丢失 [英] Parameters in the page URL are lost when clicking on any button
本文介绍了单击任何按钮时,页面URL中的参数都会丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$("#saveNews").click(function() {
alert("clicked on save");
alert(idx);
alert(id);
alert(type);
alert(subtype);
window.location = "'"+'news.html?type=' + type + '&subtype=' + subtype+'&id='+id+"'";
toSaveNews(idx);
});
function toSaveNews(index) {
alert("inside saving");
alert(index);
var newsFD = new FormData($("#fileinfonews"));
var news = $("#newsDetails").val();
alert(customer);
alert("stop");
newsFD.append("reqData1", reqData1);
newsFD.append("reqData2", reqData2);
if (news == "") {
bootbox.alert("News can't be empty.Enter something."); else {
alert('b4 ajax');
$.ajax({
type : "POST",
url : "/path1/saveNews",
data : newsFD,
processData : false,
contentType : false,
success : function(data) {
alert("success!!!!!!!!");
}
在这里,我甚至在Ajax之前就收到了警报.有3个按钮上载,返回和重置. "savenews"是上传"按钮的ID.在后退按钮中,我输入:
Here I got the alerts even before Ajax. There are 3 buttons Upload, Back and Reset. 'savenews' is the id of Upload button. In back button I put like:
<button class="btn" id="back" onclick="history.back();">Back</button>
只要我单击这些按钮中的任何一个,URL就会变为 localhost:3338/news.html?
Whenever I click on any of these buttons the URL becomes, localhost:3338/news.html?
我没有任何参数.我不知道为什么你们能给我解决方案吗?谢谢.
I didn't get any parameters. I don't know why. Can you guys please give me the solution?Thanks in advance.
推荐答案
$("#saveNews").click(function(event) {
event.preventDefault();
toSaveNews(idx);
});
//Basically,what the problem is,the form is being submitted automatically.So,prevent that using preventDefault()
这篇关于单击任何按钮时,页面URL中的参数都会丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文