Click here to Skip to main content
15,035,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir

I have an issue with below code. 
Result not showing as json data when clicking "Submit Button" which calls java Function


Example Doc no :  900 ,  484 , 923 , 865

Please advice me 

Thank you

Maideen

Below is my code


What I have tried:

ASP.NET
<form id="form1" runat="server">
       <div>
           <asp:Label ID="Label1" runat="server" Text="Enter Receipt No"></asp:Label>
           <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

       </div>
       <div>
           <asp:Button ID="btnAll" runat="server" Text="All" />
           <asp:Button ID="btnDocno" runat="server" Text="DocNo" />
            <asp:Button ID="BtnSubmit" runat="server" Text="Submit" OnClientClick="GetDetails()" />
       </div>
       <div>


JavaScript
<script type="text/javascript">
        function GetDetails(varCnNo) {
            var varCnNo = document.getElementById('<%= TextBox1.ClientId %>').value;
            alert(varCnNo);
            return true;
            const url = new URL("http://courier.silsnetwork.com/WebService.asmx/GetBizTrak_DOCNO?strDocNo=" & varCnNo);
            let headers = {
                "Content-Type": "application/json",
                "Accept": "application/json"
            };

            let body = {
                "docno": varCnNo //
            }
            fetch(url, {
                method: "POST",
                headers: headers,
                body: body
            })
                .then(response => response.json())
                .then(json => console.log(json));
        }
    </script>
Posted
Updated 17-Jun-21 23:42pm

1 solution

If this is the code you're using then straight away the HTTP request isn't going to work because you're returning from the method before it can even run:
JavaScript
alert(varCnNo);
return true;

If you get rid of the return statement then the request can process. Otherwise, have you tried also subscribing to the catch() of the Promise<> to handle when errors happen? Using the catch()[^] method can provide you a means to report errors.

Also, be aware some websites have origin restrictions for requests, so if you're running this locally or from another website then the request could be blocked for not originating from the same domain.
   
Comments
Maideen Abdul Kader 19-Jun-21 4:24am
   
Thank you
I have removed and tried, could not
if add docno in url. it is working
example: http://courier.silsnetwork.com/WebService.asmx/GetBizTrak_DOCNO?strDocNo=900
this server is just for testing temporary uploaded.

Please advice me
Thank you
Maideen
Chris Copeland 21-Jun-21 4:07am
   
Did you follow the advice I gave and subscribe to the catch() method? You've not explained the error that you're receiving.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900