Trouble parsing Ajax response data from web service in JavaScript

When I make an ajax call to a web service, it appears like this -

$.ajax({
         cache: false,
         type: 'POST',             
         url: 'callWebService.asmx/getData',
         dataType: 'json',
         data: object,
         success: function () {
             alert ("success"); },
         error: function (response) {                                    
             alert("error: " +  response.responseText);}
});

This is the code for my Web Service function -

JavaScriptSerializer serializer = new JavaScriptSerializer();
Dictionary<string, string> temp = new Dictionary<string, string>();
temp.Add("boston", "mass");
string json = serializer.Serialize((object)temp);
return json;

The error message I encounter -

Please note: The angle brackets "<" have been enclosed in parenthesis to avoid them being interpreted as code.

error: (<)?xml version="1.0" encoding="utf-8"?>
(<)string xmlns="http://tempuri.org/">{"boston":"mass"}</string>

Answer №1

From my understanding, it seems that your webservice is providing JSON data within an XML structure.

You may find this discussion useful:

Solution for ASP.NET JSON web service returning JSON wrapped in XML

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

What is the most effective way to send a list of objects to a Controller

https://i.stack.imgur.com/oyi5v.png This form is for billing purposes. You can add the item name, quantity, and price multiple times to calculate the total amount. Once you click on submit, all the included items along with other parameters like bill nu ...

Amending the Access-Control-Allow-Origin setting to enable the proper functioning of Jquery's load() function

SITUATION: Our internal web site is hosted on a web server. We also have SharePoint running on a separate internal web server. Both are within the company.com internal domain, with different sub domains accessed via SharePoint.company.com and internalWeb ...

Check domains using Jquery, AJAX, and PHP

I'm currently developing a tool to check domain availability. Here is the PHP code I have so far: <?php $domain = $_GET["domname"]; function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); ...

Having issues getting Toggle Switches to function properly in Asp.Net Webforms

I am in need of a toggle switch that can be toggled on or off depending on the user's preference. Here is a CSS code snippet that I have come across in various examples: .switch { position: relative; display: inline-block; width: 60px; hei ...

Struggling to retrieve data from AJAX call

I'm having trouble accessing the data returned from a GET AJAX call. The call is successfully retrieving the data, but I am unable to store it in a variable and use it. Although I understand that AJAX calls are asynchronous, I have experimented with ...

"Enhance your web application with dynamic drop-down selection using Spring, Ajax

In my JSP file, I have a script that populates the list of states based on the selected country. The script fetches data from the controller and is supposed to display the list of states. However, after calling the controller method, the alert "received da ...

Toastr Notification Failure in AJAX CRUD Operations

When attempting to display a toastr message in my AJAX CRUD, only the modal pops up and nothing is displayed within it. I have added all the necessary CDN links in the master layout and script tags as well. The data stored successfully in the database show ...

What are the counterparts of HasValue and .Value in TypeScript?

There is a method in my code: public cancelOperation(OperationId: string): Promise<void> { // some calls } I retrieve OperationId from another function: let operationId = GetOperationId() {} which returns a nullable OperationId, operat ...

Tips for retrieving the $(this) element within an ajax success callback function

I am encountering an issue where I am unable to access $(this) inside the jQuery Ajax success function. Below is the code snippet in question: $.ajax({ type: 'post', url: '<?php echo site_url('user/accept_deny_friendship_reque ...

The element I am specifying is not being waited for by WebDriverWait

I'm facing a challenge where I need my code to pause until a specific element appears before proceeding to extract text from it. When I manually step through the code and give enough time for the element to show up, everything works fine. However, whe ...

Triggering a JavaScript function when a page is focused due to user interaction

In my project, I have a specific requirement that involves triggering a new window to open when the user clicks on an icon. In this new window, the user should be able to view and edit certain fields. Upon closing the new window and returning to the parent ...

The Ajax request functions flawlessly on Mozilla but encounters issues on Chrome, causing confusion as it occasionally works

I am using a PHP file with a class and function to store data in the database, accessed via AJAX. While everything works smoothly in Mozilla, Chrome seems to be causing some issues. Strangely, sometimes it works fine, but other times it fails for no appare ...

Troubleshooting a problem with selecting options in Jquery

Looking for assistance with a jquery script. I have a select dropdown that fetches a list of options via Ajax. When a user clicks on an option, if a certain variable equals 1, an HTML div is added. If the variable changes to another value, the HTML div dis ...

How can I distinguish between a decimal and a long numeric token when using a custom JsonConverter with Utf8JsonReader?

I am working with a json converter that needs to convert a given property value to either a decimal or a long, depending on the type of value. However, I am facing an issue where I cannot determine if the property value is a decimal or a long since the t ...

Utilizing the jQuery library for flexible REST API requests with the incorporation

I'm currently utilizing jQuery getJSON to fetch posts from the WP API v2. There are some input fields that I'd like to make clickable, and then add extra parameters to the request URL. Here are some example requests: Posts - https://www.example ...

The click functionality appears to be malfunctioning

I encountered an issue with my code related to the click events. The problem is that one click event doesn't work after another one. Here is my ajax and jquery code: <!-- Placeholder for confirmation modal when gevonden button is clicked, then u ...

Animation will cease once the page is refreshed via Ajax

I'm facing a challenge with a problem that I can't seem to resolve. The issue lies in my use of this plugin for displaying random images. The only step left is to refresh the content within the div. However, every time I attempt to do so, the an ...

The functionality of iScroll becomes unresponsive once I implement Ajax to load the list

I have successfully implemented an iScroll list that works perfectly when coded directly into the HTML. However, when I attempt to use jQuery-Ajax to dynamically load the same list, it remains stuck at the top and refuses to scroll down to the bottom. $( ...

Utilize AJAX and jQuery to seamlessly upload files through the PHP API

I have code in the following format. PHP file : <form action="http://clientwebapi.com/createEvent" id="form_createEvent" method="post" enctype="multipart/form-data"> <input type="text" name="image_title" /> <input type="file" name="media" ...

Updating DOM element value from controller in AngularJs following an AJAX request

Currently, I am facing an issue in my code where I want to display a progress bar and hide it until isLoaded becomes true. <uib-progressbar class="progress-striped active" value="100" type="warning" ng-hide="{{isLoaded}}"></uib-progressbar> I ...