why when ajax jquery call applied it call OnGet and not call OnGetshiftDataUp ?

Ahmed Abd El Aziz 315 Reputation points
2023-06-23T20:07:33.6033333+00:00

I work on razor asp.net . i face strange issue when apply ajax request it catch OnGet function get method 

but correct or what I expect is to hit or catch OnGetshiftDataUp

why it catch on get and not catch OnGetshiftDataUp 

when apply jquery ajax request it not catch  OnGetshiftDataUp and catch OnGet why that happen 

i write on url url: 'ShelfLabelPrinterSetUp?handler=shiftDataUp' so why it go to OnGet

full code sample

$('#save-btn').click(function () {

                var param1Value = $('#editshelflabelModal #edit-ip').val();

                console.log(param1Value);
                $.ajax({
                    url: 'ShelfLabelPrinterSetUp?handler=shiftDataUp',
                    type: "GET",
                    dataType: "json",

                    data: { serverip: param1Value },
                    success: function (result) {
                        alert(result);
                    },
                    error: function (xhr, status, error) {
                        console.log(error);
                    }
                });
            });
public ActionResult OnGetshiftDataUp(string serverip)
        {

           return new JsonResult("Success");

        }
public void OnGet()
        {
        }

<div class="modal fade" id="editshelflabelModal" tabindex="-1" role="dialog" aria-labelledby="userDetailsModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <h5 class="modal-title" style="text-align:center;">


            </h5>
            <div class="modal-header">
                <h5 class="modal-title" id="editshelflabelModaldata" style="margin-left:200px;">Hi,@TempData["UserID"]</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <form id="edit-form">
            <div class="modal-body">


                    <div class="form-group">
                        <label for="edit-server">Server IP</label>
                        <input type="text" class="form-control" id="edit-ip" name="serverip">
                    </div>
                    <div class="form-group">
                        <label for="edit-printer">Printer Name</label>
                        <input type="text" class="form-control" id="edit-printername" name="printername">
                    </div>
                    <div class="form-group">
                        <label for="edit-locationsdata">Location Name</label>
                        <input type="text" class="form-control" id="edit-Location"  name="Location">
                    </div>




            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" id="save-btn">Save changes</button>

            </div>
            </form>
        </div>

    </div>

</div>
Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2023-06-23T20:44:00.95+00:00

    I work on razor asp.net . i face strange issue when apply ajax request it catch OnGet function get method

    I explained the errors in your code and provided a working example in your previous post.

    https://learn.microsoft.com/en-us/answers/questions/1315647/error-404()-when-try-to-make-ajax-request-with-typ

    The handler needs a capital "S" in Shift.

            public ActionResult OnPostShiftDataUp()
            {
                return new JsonResult(new { serverip  = serverip , printername = printername , Location  = Location });
                //return Page();
    
            }
    

    The AJAX URL is simply.

    url: '?handler=ShiftDataUp',
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.