0

I want to get the text by entering any id in the textbox like 0, 1 or 2. It's not showing when I press the button Get by Id.

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<input type="text" name="name1" id="text1" value="" />
<input type="button" name="name2" id="btn1" value="Get by Id" />

<script>

 $("#btn1").click(function () {
        var id = $("#text1").val;
            $.getJSON("/api/Customer/" + id, function (data) {
                alert(data);
            });
    });

</script>
1
  • 2
    How specifically is this failing? Are there any errors in your browser's development console? When you use your browser's debugger, is the JavaScript code executed at all? Is the click handler invoked? Does id have the value you expect? Is the AJAX call made? What is the server's response? Please provide information about the problem. At least at a quick glance, you're not invoking the val() function properly. It should be $("#text1").val(). Commented Jan 2, 2019 at 16:12

2 Answers 2

1

on the line below click, use this

var id = $("#text1").val();
Sign up to request clarification or add additional context in comments.

Comments

1

Try this $("#text1").val() instead of $("#text1").val;

Your missing the function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.