Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
How to call GET Api with input param use JQuery and JavaScript in Asp.net view when a special tag load

Hi I want to load count of orders in my view (in a special tag), I wrote a SP in Sql which return count of order according to input type. I design several box in my form to show all types order count. So I give "Id" to my tag and I want when form loads, this tag show the number. I wrote a script at the bottom of my view. View and script and controller :

     <div class="inner">
            <h3 id="Orders1"><sup style="font-size: 20px"></sup></h3>
            <p>New Orders </p>
     </div>

<script>
    $("#Orders1").load(
    function () {
        $.ajax({
            url: '/Report/GetResultTestData',
            data: JSON.stringify({
                id: 1 /// input value 
            }),
            type: 'GET',
            contentType: 'application/json; charset=utf-8'
        }); 
   </script>

And My controller is like bellow :

    [HttpGet]
    public IActionResult GetResultTestData(int id )
    {
        var data = _sv.GetResultTestData(id);

        return new JsonResult(data);
    }

but unfortunately it doesn't show anything would you please guide me!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Update

  <div class="inner">
            <h3 id="Orders1"><sup style="font-size: 20px"></sup></h3>
            <p>New Orders </p>
            <span id="result2"></span>//add the id to put the result id
     </div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>

      $(document).ready(function () {                  
        $.ajax({
            url: '/Report/GetResultTestData',
            data: {id: 1},
            type: 'GET',
            contentType: 'application/json; charset=utf-8',
            success: function (result) {
                    $('#result2').html(result);
                }// add the success to pass the result
        });
      });
   </script>

Controller:

    [HttpGet]
    public IActionResult GetResultTestData(int id )
    {
        return Content(id, "text/plain");
    }

Result:

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!