The issue of jsonp encountering an error 500 in the asmx

After testing this code, it's working perfectly fine for me.

 function test() {
    debugger;
    $.ajax({ url: "http://testweb.com/myAPI.asmx/GetPersonTest",
    type: "GET",
    contentType: "application/json; charset=utf-8",
    data: { userid: 1 },
    dataType: "jsonp",
    success: function(json) {
        alert(json.UserID + ' ' + json.FirstName + ' ' + json.LastName);
    },
    error: function() {
        alert("Hit error fn!");
    }
    });
}

Within the same asmx file, there is another method as shown below

    function Post_test(){

var newURL = window.location.protocol + '//' + window.location.host + '/' + window.location.pathname;
var user = document.getElementById('Username').value;
var email = document.getElementById('email').value;
debugger;
$.ajax({ url: "http://testweb.com/myAPI.asmx/GetPerson",
    type: "GET",
    contentType: "application/json; charset=utf-8",
    data: JSON.stringify({ username: user, emailID: email}),
    dataType: "jsonp",
    success: function(json) {
        alert(json.UserID + ' ' + json.FirstName + ' ' + json.LastName);
    },
    error: function(json) {
        alert("Hit error fn!");
    }
});


}

This method performs an insert into a database and returns the same output as GetPersonTest. However, when I try to call it using JavaScript and JSONP, it results in a 500 server error.

Upon checking in the debugger, the following error message is displayed

jQuery17106155389654450119_1401518867750({"Message":"Invalid web service call, missing value for parameter: \u0027username\u0027.","StackTrace":"   at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n   at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n   at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"});

If anyone can provide assistance on the above, that would be greatly appreciated. Thank you.

The header of the method is as follows

         <WebMethod(True)> _
    <ScriptMethod(UseHttpGet:=True, ResponseFormat:=WebMessageFormat.Json)> _
        Public Function GetPerson(ByVal username As String, ByVal emailID As String) As String

End Function

Also, when inspecting the header in the developer tool, it shows the following information

callback:jQuery17106155389654450119_1401518867750
{"username":"testuser","emailID":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="671302141327130214134904080a">[email protected]</a>"}:
_:1401518889467
Response Headersview source

Answer №1

Make sure to verify that the username parameter is correctly utilized in the specified contract method. The error indicates a possible absence of this username parameter.

Double-check this and provide your response promptly.

Answer №2

Could you please incorporate the following modifications :

  • Eliminate 'JSON.stringify' from the data parameter, so it should appear as

    data: {"username": user, "emailID": email}

  • The response format specified is "WebMessageFormat.Json", hence switch the dataType to "json" instead of "jsonp".

  • Since the data is sent as a querystring and not JSON, you can omit the entire "contentType" (or simply remove 'application/json').

I trust that this guidance will be beneficial.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A dynamic 3-column layout featuring a fluid design, with the middle div expanding based on the

Sorry for the vague title, I'm struggling to explain my issue clearly, so let me elaborate. I am using flexbox to create a 3-column layout and want the middle column to expand when either or both of the side panels are collapsed. Here is a screenshot ...

DoubleClicking on Checkbox Causes jQuery Click Event to Trigger Twice

Experimenting with DataTables, I have created a table setup like this: <table id='dt'> <thead><!-- Some Header --></thead> <tbody> <tr data-lineid=1> <td><input type=' ...

How can one determine if the key and certificate are being utilized?

I've been developing the Express API Javascript code with a self-signed SSL certificate. To create the certificate, I followed this guide: After generating the privateKey.key, certificate.crt, and server.js, I placed them in the same folder. In my ...

Enter the text within the TypeScript file where the cursor is positioned

I am interested in exploring certain inferred types within TypeScript code. This would be particularly beneficial for ensuring that the inferred types are precise, specific, and accurate in correct files. Is there a way to retrieve the type at a specific ...

Place a vertical slider adjacent to an HTML element on either the left or right side

I'm struggling to bind a range slider to the left or right side of a canvas that displays video. Despite my efforts, CSS seems to be putting up a strong fight. I can handle issues like stretching and slider values, but attaching it to the canvas is pr ...

Angular: Failure in receiving EventEmitter's event with .subscribe method

My current challenge involves handling an event coming from NgLoopDirective within the method EV of NgDNDirective. I am attempting to achieve this by passing the EventEmitter object by reference and then calling .subscribe() as shown in the code snippet be ...

MERN Stack deployment to Heroku: Remote rejected - unable to push changes to master branch (pre-receive hook declined)

Just a heads up: I've successfully deployed using this method around 3 times in the past, but now it seems to be failing. Could there have been an update with Heroku that's causing this issue? Not entirely sure... I'm attempting to push my ...

It appears that there is a slight hiccup in the code when JavaScript is implementing the line skip functionality for the condition

Currently, I am working on a textbook exercise that involves the classic 99 Bottles of Beer on the wall JavaScript program. However, this assignment does not come with any examples or answers for reference. Despite searching online for assistance, the code ...

javascript functionality may be affected in Internet Explorer and Firefox following the upgrade to jquery version 1.8.3

After upgrading to jquery 1.8.3 from jquery 1.7 (where everything was functioning properly in all browsers), I added a javascript plugin that specifically requires jquery 1.8.2 or 1.8.3 Unfortunately, the image resizing functionality of this javascript is ...

The spreading of personalized events

I am expecting my CustomEvent to be propagated from the document to all the DOM elements. However, for some unknown reason, it is not happening. Can you point out what mistake I might be making? <html> <script> function onLoad() { var myDi ...

When using Array.reduce(), group objects by a specific field and include all other fields in the corresponding grouped object

I'm trying to develop a group-by function for an object, where I can group an array based on a field and then merge all fields of the grouped documents from the array with their corresponding group-object fields. const groupInDoc = (array, fieldname) ...

Maintaining the selected option on page refresh with React Remix

I have a dropdown menu with 2 choices (en, no) for switching the language when onChange event occurs. To save the selected language, I am using localStorage. Due to the server-side rendering in Remix, direct access to localStorage is not possible. Therefo ...

"Utilizing jQuery's .ready function to determine the height of an

Although it may seem like a simple question, I've encountered an issue with jQuery. Every time I try to get the height of an element within a .ready function, the value returned is always zero. $(function() { $('#my-elem').height() // Alw ...

Generate a custom map by utilizing JavaScript and HTML with data sourced from a database

Looking for guidance on creating a process map similar to this one using javascript, html, or java with data from a database. Any tips or suggestions would be appreciated. https://i.sstatic.net/tYbjJ.jpg Thank you in advance. ...

The issue of a false value not being correctly matched in Jasmine is causing problems

Currently, I am utilizing the following code to evaluate an element with aria-checked="false". expect((accessPolicyPage.listSelectAll).getAttribute("aria-checked")).toEqual("false"); The output is presenting as Expected [ 'false' ] to equal &ap ...

How can I include a RegisterPostbackControl in an AsyncPostback for a Telerik RadGrid?

On a RadGrid page with a master page containing an UpdatePanel around the Content, I have successfully registered postback control for Export buttons using the code below: Private Sub uxGrid_ItemCreated(ByVal sender As Object, ...

Is there a way to extract individual values from a for-each loop in JavaScript?

Would appreciate any guidance on my use of Bootstrap vue table with contentful's API. I'm currently working on implementing a for loop to iterate through an array and retrieve the property values. Although the console.info(episodes); call success ...

Upon clicking on an empty asp:textbox, my goal is to promptly hide the visibility of an asp:label

How can I make the visibility of an asp:label false immediately when clicking on an empty asp:textbox? I have set some labels for validation, but they only become visible when the textbox is empty. Unfortunately, they do not hide when the text is changed o ...

The attempt to load a JavaScript resource has resulted in an error: the file was not located, despite the fact that it is a

Recently, I came across a new challenge in my application. Whenever I navigate to specific pages, I notice an error message in the development console: inject.preload.js:373 GET blob:http://my-app-name.test/ba65127c-383e-45b7-8159-9b52ea288658 0 () Upon ...

What is the process for transferring a JSON data object to the server with JavaScript XMLHttpRequest?

When I attempt to send an XMLHttpRequest to a PHP server, I am encountering difficulties in getting the $_POST or $_REQUEST object to be filled with the data I am sending using JavaScript: var r = new XMLHttpRequest; r.open("POST", "http://url.com", true ...