Click here to Skip to main content
15,884,933 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Try to call webapi using asp.net .
while calling javascript function by onclick event from client side .it is not working with below code

Please give me solutions for this.

What I have tried:

JavaScript
//  document.getElementById("button1").onclick = function () { myFunction() };
        $(document).ready(function () {
            $('#Button1').on('click', function () {
                alert('onclick is working.');
                    var Eid = $('#TextBoxEId').val();
                  var Epwd = $('#TextBoxPwd').val();
                MyReport(); //Your function 
            });
        });
           
            function MyReport(){
                    $.ajax({
                        type: "POST",
                        url: "https://converbiz-professional-api.herokuapp.com/api/v1/users/login",
                        data: { data: Eid },
                        success: function (result) {
                            if (result != null) {
                                $('#TextBoxEId').text(result.Eid);
                                $('#TextBoxPwd').text(result.Epwd);
   
                                $('#picoutput').html(result);
                            });
                    
                            }
                        error: function (err) {
                            alert(err.statusText);
                        }
                   });
        }
Posted
Updated 16-Nov-17 3:26am
v2
Comments
Suvendu Shekhar Giri 16-Nov-17 8:36am    
Check for the errors in the developer mode of your browser and in console section. Let us know what error are you getting?

1 solution

you have declared Eid and Epwd inside the button click event and you are trying to access the variables inside another method, so the value will be undefined and moreover in the data attribute of the ajax method you are passing only one parameter make sure you are passing all the values.
pass the Eid and Epwd values to the function as arguments and access it in the function declaration
var Eid = $('#TextBoxEId').val();
      var Epwd = $('#TextBoxPwd').val();
    MyReport(Eid, Epwd); //Your function

function MyReport(Eid,Epwd){
                  $.ajax({
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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