Having trouble passing multiple parameters in a jQuery AJAX request?

I'm currently working on implementing a .NET web service (asmx) using JSONP with guidance from this helpful tutorial.

When I try calling my webservice with only one parameter, everything runs smoothly. However, the moment I attempt to call it with multiple parameters, I encounter a frustrating Network 500 error. I attempted to apply the solution mentioned in this Stack Overflow thread: Pass Multiple Parameters to jQuery ajax call, by using

"data: JSON.stringify({ jewellerId: filter, locale: 'en-US' }),"
. Alas, it failed to work.

Here is the script I have been working with:


function getData() 
{
    var key = "123";
    var code = "12458";
    jQuery.ajax({ url: http://service.com/test.asmx,
        data: JSON.stringify({ Key: key, Code: code }),
        dataType: "jsonp",
        success: function(json) 
        {
            alert(json.d);
        },
        error: function() {
            alert("Hit error fn!");
        }
    });
}

After making adjustments to the webservice to accept only one parameter, and modifying the data accordingly like so:

data: {Key: JSON.stringify("123") }
, everything worked perfectly.

Any advice or suggestions on how I can resolve this issue would be greatly appreciated.

Answer №1

Avoid converting the data into a string format when making GET requests, especially for jsonp requests.

function fetchData() {
    var id = "456";
    var name = "John";
    jQuery.ajax({ url: http://example.com/api/test.asmx,
        data: { ID: id, Name: name },
        dataType: "jsonp",
        success: function(response) {
            alert(response.data);
        },
        error: function() {
            alert("An error occurred!");
        }
    });
}

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 guide on retrieving and resetting the value of a radio button within a table

I need to create multiple radio buttons within a table using Razor syntax under ASP.NET Core MVC. Each row of the table should have an update and clear link to update the record and clear the selected radio button for that specific row. <table class=&qu ...

Python script to extract data from a JSON file

Struggling to read data from a JSON file and display the values? Having trouble figuring out how to access all the values from the first dictionary in the list? Here's what you want to print: website: https://www.amazon.com/Apple-iPhone-GSM-Unlocke ...

JQuery function fails to execute upon first page load

I am currently facing a situation where I need to wait for a specific image to load before either swapping out its src or showing/hiding the next image. The desired outcome is to display a placeholder image (silhouette) until the main image loads, then hi ...

Provide the option to assign values on select options in order to choose specific JSON data

When working with JSON data from an API, I am creating a dynamic select element. The goal is to change some content (text and image src) based on the option selected from this select element. I have successfully populated the select options with names usi ...

Is there a more efficient method for writing my jQuery code that follows a step-by-step approach?

I have developed a step-by-step setup process that guides users through various sections. Instead of using separate pages for each step (like step1.php, step2.php, etc.), I have all the code contained in one page named setup.php. This is achieved by utiliz ...

"Successfully made an Ajax request to the web handler, however, the response did not

Within my ASP.NET project, I have a Generic handler with the following code: public void ProcessRequest ( HttpContext ctx ) { try { ctx.Response.ContentType = "text/json"; var jsonData = new StreamReader(ctx.Request.InputStrea ...

The struggles of using a jQuery tree with JSON data are real, especially when it comes to dealing with the

I am in the process of creating a tree structure from JSON data that is dynamically loaded from PHP files. However, I am facing difficulty in navigating to the third level of the tree. Below is the code snippet: $(document).ready(function() ...

Implementing JSON Serializer Settings at a Global Scale in ASP.NET MVC

The navigation properties in Entity Framework are causing an exception of "Circular Object Reference" when the collection in my View Model is being serialized by Kendo Grid. Despite setting "ReferenceLoopHandling" to "Ignore" globally in my Application_Sta ...

Having trouble with parsing JSON data in Swift?

I've been attempting to utilize Swifty JSON for parsing a local file. While I am able to successfully store content in the data variable, I seem to be encountering issues when trying to use JSON from the SwiftJSON framework as it is not storing any co ...

Having trouble with my basic AJAX request; it's not functioning as expected

I am currently diving into the world of Ajax and I've hit a roadblock: 1. HTML : <body> <form> Username: <input type="text" id="username" name="username"/> <input type="submit" id="submit" /> </form> <scrip ...

New update: Adjusting the chart by using the slider to modify the date values on the x-axis

Update: I have made changes to the question, the issue with values not appearing on the x-axis has been resolved. Now, as the slider is moved, the data on the graph remains constant and I can see changing x values. I am currently working on incorporating ...

Is there a way to obtain a compressed file using an archiver from a POST request?

Currently, I am developing a NodeJS API using Express where upon sending a POST request, it should create a TAR file based on the body of that request. Issue: While I can access and manipulate the body of the request during a POST endpoint, I am unable ...

Attempting to retrieve JSON data and present it in a grid layout

I have a JSON file with the following data: { "rooms":[ { "id": "1", "name": "living", "Description": "The living room", "backgroundpath":"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSrsU8tuZWySrSuRYdz7 ...

Using a URL in the fill property is a simple process that involves specifying

Here is the snippet of the code I'm working with: <?xml version="1.0" standalone="no"?> <html> <head> <style> .someClass { fill:"url(#Pattern)"; } </style> ...

Generate instances of the identical class with distinct attributes

Is it possible in Java to create objects of the same class with different variables each time? For instance: I have a method that retrieves data from a URL containing a JSON file, and I want to use this data to create a post object. ObjectMapper mapper ...

The cross-domain AJAX request fails to receive a response

I am currently working on validating PAN card details. I am utilizing an AJAX call to verify the PAN card entered by the user, sending the PAN number to this URL: . The data is being sent to the following URL using AJAX call: function callbackFnc(data) { ...

Dominant Editing through ASP.Net Roles

Looking for guidance on how to effectively use knockout with asp.net membership roles in MVC 4. My goal is to incorporate an editable grid on the page based on whether the user is an administrator or a 'registered user'. I want to ensure that use ...

JavaScript JSON YouTube API viewCount function is not functioning correctly

I'm struggling to retrieve the views of a video using JavaScript (Chrome Extension). Here is the code I have so far: $(function() { $.getJSON('http://gdata.youtube.com/feeds/api/videos/H542nLTTbu0?alt=json',function(data) { ...

Get all the classes from the body element of the AJAX-loaded page and update the body classes on the current page with them

I am currently in the process of AJAX-ing a WordPress theme with a persistent music player. In Wordpress, dynamic classes are used on the <body> tag. The structure I'm working with looks like this: <html> <head> </head> ...

Require the capability to bypass inline CSS styling

Currently facing an issue with a wordpress website I am constructing using iThemes Builder. The problem arises when integrating the plugin Jquery Megamenu, as the drop-down menu gets truncated due to an overflow:hidden property that cannot be overridden i ...