PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 8, 2022

[FIXED] How to call onget method with parameters in .net core using ajax

 September 08, 2022     ajax, asp.net-core, c#, jquery     No comments   

Issue

I tried to call this onget method in .net core using ajax call but this method hitting without parameters

 public void OnGet(string id,string refundReason ,int amount)
        {           
           
        }

I used these 2 ajax call but not passing parameter values

$.ajax({
    url: "https://localhost:7197/Transactions/Refund?id="+'20a63762-a6ab-4edb-852b-fd247e9dc247'+"&refundReason="+refundReason+"&amount="+amount,
    type: "GET",              
    dataType: "json",
    traditional: true,
    contentType: "application/json; charset=utf-8",
    success: function (data) {
      debugger;
      
    },
});

this one alse tried not passing values to onget method. let me know what changes i've to do. Thanks

 $.ajax({
        url: "https://localhost:7197/Transactions/,
        type: "GET",       
        data: JSON.stringify({ id: '20a63762-a6ab-4edb-852b-fd247e9dc247',
                               refundReason:'tt',
                               amount:"1"
                            }), 

Solution

You should just be able to call it with $.get and passing the values in the query string. GET calls do not accept body data.

$.get(`https://localhost:7197/Transactions/Refund?id=20a63762-a6ab-4edb-852b-fd247e9dc247&refundReason=${refundReason}&amount=${amount}`, response => {
    ...
});


Answered By - hawkstrider
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing