Jquery 单击任何按钮时,页面URL中的参数将丢失
在这里,我甚至在Ajax之前就收到了警报。有3个按钮上载、返回和重置。”savenews'是上载按钮的id。在“后退”按钮中,我放置了如下内容:Jquery 单击任何按钮时,页面URL中的参数将丢失,jquery,Jquery,在这里,我甚至在Ajax之前就收到了警报。有3个按钮上载、返回和重置。”savenews'是上载按钮的id。在“后退”按钮中,我放置了如下内容: $("#saveNews").click(function() { alert("clicked on save"); alert(idx); alert(id); alert(type); a
$("#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!!!!!!!!");
}
返回
每当我点击这些按钮时,URL就会变成,localhost:3338/news.html?
我没有得到任何参数。我不知道为什么。你们能给我一个解决方案吗?提前谢谢
<button class="btn" id="back" onclick="history.back();">Back</button>
有太多的“
请尝试以下方法:
window.location = "'"+'news.html?type=' + type + '&subtype=' + subtype+'&id='+id+"'";
如果你的url中有空格,你应该删除它
无法更改反向导航的参数。返回导航始终指向最后一页:
window.location = 'news.html?type=' + type + '&subtype=' + subtype+'&id='+id;
URL:news.html?type=1
->(导航到)URL:news.html?type=2
history.back()
将简单地加载浏览器历史记录中的上一个URL。是的..这不是问题..但为什么URL中缺少参数..我如何避免这个问题?我如何用小提琴向您显示..我是这个领域的新手。。注册,把你的代码放在这里,给我们URL我知道了谢谢$(#saveNews”).click(函数(事件){//click event在这里生成event.preventDefault();//因为这是一个表单,所以当我们单击//时它会被提交。所以,请防止它被提交。现在它对saveNews(idx);}工作正常;是否更改了window.location字符串?什么是警报(类型)代码>打印?如果将其更改为:window.location='news.html?type=1'代码>没有任何变量?这是我在单击任何按钮之前的url:所有警报结果都很好。“这可能是因为表单中的信息是作为post提交的,它不会在url上放置任何参数”。我在某个地方找到了这个..还是问题:你删除了““+””“
”了吗?对不起,我再也帮不上忙了。看这把小提琴,它正常工作:。还有一些逻辑错误<代码>toSaveNews(idx)代码>将永远不会被调用,因为您以前进行过重定向。
URL: news.html?type=1
-> (navigate to) URL: news.html?type=2
<- (history.back() called) URL: news.html?type=1
$("#saveNews").click(function(event) {
event.preventDefault();
toSaveNews(idx);
});
//Basically,what the problem is,the form is being submitted automatically.So,prevent that using preventDefault()