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

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


Below is my code

What I have tried:

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

           <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()" />

<script type="text/javascript">
        function GetDetails(varCnNo) {
            var varCnNo = document.getElementById('<%= TextBox1.ClientId %>').value;
            return true;
            const url = new URL("" & 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));
Updated 18-Jun-21 0:42am

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:
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.
Share this answer
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
this server is just for testing temporary uploaded.

Please advice me
Thank you
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