0

I am developing a website in which only 1 html page is there in which I first fethch the url & gets the id from url and send it to api using ajax call. On success, I displays data of the given id from url.My code is as-

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            $('#main').hide();

            var url = window.location.href;
            var formno = url.substr(url.lastIndexOf('/') + 1);

            if (formno != 'Login.html') {              
                var apiUrl = 'http://localhost:801/api/api/Patient/Get';    
                $.ajax({
                    url: apiUrl,
                    crossDomain: true,
                    contentType: "application/json",
                    type: 'GET',
                    data: { formNo: formno },
                    success: function (result) {                           
                        $('#main').show();
                        alert("Success" + result)
                    },
                    error: function (result) {
                        alert("error :: " + JSON.stringify(result))
                    }
                });    
            }    
        });      
    </script>

when I use the url as abc.in#1 it displays the success alert but I want to give the url in format abc.in/1 at that time it gives

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Why it can not find the page? Is there any solution for this? I want to give plain url as abc.in/1 where 1 is id and which is dynamic. Is there any solution?

Sayli Vaidya
  • 179
  • 1
  • 14
  • 1
    if you end the url with `/1` then your web server will be looking for a sub folder named `1`. The first implementation you have, using hashes, is perfectly normal and quite frankly a simpler approach. It means you stay on the same page all the time, whereas your approach means jumping from page to page and handling pages that don't exist. – Reinstate Monica Cellio May 14 '15 at 12:35
  • abc.in/1 is requesting a page called "1", which does not exist. You probably want to use a query string like, abc.html?id=1 and then capture the parameter. See this post: [How can I get query string values in JavaScript?](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – Yogi May 14 '15 at 12:42

1 Answers1

0

Your browser is probably trying to access document on location abc.in/1, which doesn't exist. You will need some server side logic for this, e.g. php router which will always serve your document, and additonal parameters will be processed by it. abc.in#1 anchor is different type of url parameter, which purpose is to be processed by document or javascript on client side.

vlatkokaplan
  • 352
  • 1
  • 7