0
$("#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!!!!!!!!");

        }

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>

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.

Divya
  • 31
  • 1
  • 9

2 Answers2

0
window.location = "'"+'news.html?type=' + type +     '&subtype=' + subtype+'&id='+id+"'";

There are to many '' try this:

window.location = 'news.html?type=' + type +     '&subtype=' + subtype+'&id='+id;

Then if there are white spaces in your url, you should decode it.

Is it not possible to change a parameter for a back navigation. The back navigation always points to the last page:

URL: news.html?type=1 
-> (navigate to) URL: news.html?type=2 
<- (history.back() called) URL: news.html?type=1 
Community
  • 1
  • 1
Jan Hommes
  • 5,122
  • 4
  • 33
  • 45
  • have you changed the window.location string? What does `alert(type);` print? What if you change it to: `window.location='news.html?type=1';` without any var? – Jan Hommes Aug 05 '13 at 07:38
  • this is my url before clicking any button:All the alerts results fine..http://localhost:3338/news.html?type=mvs&subtype=now&id=2475c35886b2144d8e0354e894002819&index=1 – Divya Aug 05 '13 at 07:40
  • "This is probably because the information from the form is submitted as a post, which doesn't place any parameters on the URL". i found this somewhere.. – Divya Aug 05 '13 at 07:45
  • Still the question: Have you removed the `"'"+ +"'"`? – Jan Hommes Aug 05 '13 at 07:48
  • sorry i can't help anymore. See this fiddle, it normally work: [fiddle](http://jsfiddle.net/uP7KK/2/). There are also some logic mistakes. `toSaveNews(idx);` will never be called because you making a redirect before. – Jan Hommes Aug 05 '13 at 09:39
  • ok ...I got it.. $("#saveNews").click(function(event) {//click event is generating here event.preventDefault();//as this is a form it is being submitted when we click //on.SO,prevent that from being submission.Now it's working fine toSaveNews(idx); }); – Divya Aug 05 '13 at 09:59
0
$("#saveNews").click(function(event) {
                                        event.preventDefault();
                                        toSaveNews(idx);
                                    });
                                    //Basically,what the problem is,the form is being submitted automatically.So,prevent that using preventDefault()
Divya
  • 31
  • 1
  • 9