1

Is it a possible using windows.location.replace to redirect to ItemID. Like, I have one input text and button and when user input like 123 and if this item exist in database it need to redirect to this item.

$.ajax({          
            type: "GET",            
            URL: "/api/Akontas/GetAKONTA",
            data: { id: $('#AkontasId').val() },
            contentType: "data/xml; charset=utf-8",  
            success: function (result) {
                window.location.replace("http://localhost:57285/api/Akontas/" + $('#AkontasId'));
            },
            error: function () {
                alert("Ne postoji AKONTO pod tim rednim brojem");
            }
        });

Something like this if exsist return xml data enter image description here

Otherwise return No data found with this ID

enter image description here

Update

enter image description here

enter image description here

  • 1
    on redirect you forgot `val()` so use `$('#AkontasId').val()` – Devsi Odedra Sep 12 '19 at 07:21
  • try `window.location.href` instead of `.replace`, this question will probably get closed I am afraid as it has been asked hundreds of times before. – GrahamTheDev Sep 12 '19 at 07:22
  • 1
    Possible duplicate of [How do I redirect to another webpage?](https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage) – GrahamTheDev Sep 12 '19 at 07:23
  • @GrahamRitchie You didnt get point. I want to redirect base on input ID Is it possible in windows.location.href pass ID –  Sep 12 '19 at 07:24
  • explain further? redirect base what? – GrahamTheDev Sep 12 '19 at 07:24
  • to pass the ID you can just concat the string - so you would build the URL as `'http://url.com/' + yourVar` – GrahamTheDev Sep 12 '19 at 07:26
  • see what Devsi wrote, he has pointed you to why it isn't working, I was trying to answer the 'is it possible' part of your question. – GrahamTheDev Sep 12 '19 at 07:27
  • Look at last two picture and you will se what I need –  Sep 12 '19 at 07:29
  • Sorry bud I must be being thick...it looks like you are asking how to redirect to the page with a certain ID, Devsi gave you the answer why your code isn't redirecting and I gave you how to build the strings and a general answer, what isn't working if you do as Devsi suggests and change `window.location.replace("http://localhost:57285/api/Akontas/" + $('#AkontasId'));` with `window.location.href("http://localhost:57285/api/Akontas/" + $('#AkontasId').val());` – GrahamTheDev Sep 12 '19 at 07:31
  • Uncaught TypeError: window.location.href is not a function –  Sep 12 '19 at 07:35

1 Answers1

0

You need to change the line from this:

window.location.replace("http://localhost:57285/api/Akontas/" + $('#AkontasId'));

to this:

window.location.href = "http://localhost:57285/api/Akontas/" + $('#AkontasId').val();