javascript - Extract data from current URL and use it in ajax call as a paramenter -
i developing website in 1 html page there in first fethch url & gets id url , send api using ajax call. on success, displays data of given id url.my code 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 use url abc.in#1 displays success alert want give url in format abc.in/1 @ time gives
http error 404.0 - not found resource looking has been removed, had name changed, or temporarily unavailable. why can not find page? there solution this? want give plain url abc.in/1 1 id , dynamic. there solution?
your browser trying access document on location abc.in/1, doesn't exist. need server side logic this, e.g. php router serve document, , additonal parameters processed it. abc.in#1 anchor different type of url parameter, purpose processed document or javascript on client side.
Comments
Post a Comment