Why does my JavaScript only trigger my web service request when I set a breakpoint?

Can you help me understand why my JavaScript code only calls my webservice when I set a breakpoint on the line ].getJSON, but not if I remove the breakpoint?

$(function () {
            $("#" + @Model.BidObjectId).submit(function () {
                 alert("Test");
                 $.getJSON("http://localhost:11523/Service1.svc/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="400725340229240f222a2523347f29247d000d2f24252c6e0229240f222a2523340924">[email protected]</a>", function (data) {
                    alert(data)
                });
            });
        });

The test alert always shows up, but the breakpoint in my svc file is never reached unless I put a JavaScript breakpoint in Chrome on the line ].getJSON...

Here is the code in my webservice

public List<BidObject> GetBidObject(string id)
        {
            List<BidObject> list = new List<BidObject>();
            list.Add(new BidObject() { BidObjectId = 1, Title = "Name" + id, Date = DateTime.Now });
            return list;
        }

[OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "/GetBidObject?id={id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        List<BidObject> GetBidObject(string id);

Answer №2

The issue has been resolved

To fix the problem, I simply included a return false statement in the javascript code. However, the exact reason behind this solution remains unknown to me.

$(function () {
            $("#" + @Model.BidObjectId).submit(function () {
                 alert("Test");
                 $.getJSON("http://localhost:11523/Service1.svc/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8fc8eafbcde6ebc0ede5eaecfbb0e6ebb2cfc2e0ebeae3a1cde6ebc0ede5eaecfbc6eb">[email protected]</a>", function (data) {
                    alert(data)
                });
                return false; // To prevent browser submission
            });


        });

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

Using JSON_ENCODE may attempt to evade double quotes

I have a controller that retrieves data from my database, formats it as valid JSON, but the HTTP response is text/html instead of application/json. This causes issues with getJSON not working properly. Should getJSON work regardless? public function send ...

Use various onChange functions for sliding toggle

I need assistance with a toggle app I'm developing that includes two slide toggles. Even though I have separate onChange() methods for each toggle, toggling one slide-toggle also changes the value of the other slide toggle. The toggle state is saved i ...

Can you transform text with accents into plain ASCII characters?

I am seeking a solution in Javascript to convert accented letters and various encodings into plain English ASCII characters. The goal is to achieve the following transformations: éclair ~becomes~ eclair bär ~becomes~ bar привет ~becomes~ privet ...

How can I pass an object into EJS templates from views in Express 3.x?

Currently, I am utilizing ejs templates in combination with node.js and express 3.x. Is there a way to display the data object that is passed into the view? Can it be achieved similar to this example in index.ejs: <%= dump(session) %> ...

Tips for creating multiple popups using a single line of JavaScript code

I am new to JavaScript and I am attempting to create a popup. However, I am facing an issue in opening two divs with a single line of JavaScript code. Only one div opens while the other remains closed despite trying various solutions found on this website. ...

Sending data as a string in an AJAX request

I have been struggling with this coffeescript function that controls dynamic select boxes. I am trying to pass the content of "modelsSelect" to another script, but for some reason, it's not working as intended. customScript.coffee dynamicSelection = ...

Converting values into keys and vice versa in JavaScript: A comprehensive guide

I have an array of Objects where I want to convert the first value into a key and the second value into a value. Please review the question below along with my desired output: [ { "name": "Unknown", "value": "R ...

What is the process for implementing a fallback image in Material UI?

Hey there! I'm currently looking to customize the fallback image of a Material UI Avatar with my own original image. Does anyone have any tips on how I can achieve this? const fallbackImage = "../../fallback/img.png" const AvatarWithBadge = ...

Is it viable to execute a reload on the same location and subsequently activate a click function?

Is it possible to combine a click function with a location reload and then trigger another click function? Please see the code example below: $('.ui-button').click(function () { location.reload(); $('#Sites').t ...

Guide to rendering a div class conditionally in a Razor page depending on a variable?

How can I dynamically render a div with different classes in Angular based on a condition? <div class="@(myArray.length>0 ? "col-md-8" : "col-md-12" )"> I'm trying to achieve that if the length of myArray is greater than 0, then it should h ...

What is the best way to fetch the class name of an element in JSDOM?

In my current project, I am facing a challenge with extracting the className of an element using JSDOM. Despite being able to locate the element successfully, I have been unable to find any relevant examples or documentation on how to retrieve the classN ...

In order to maintain a custom tooltip in an open state until it is hovered over, while also controlling its

When hovering over the first column of the table, a tooltip will appear. Within each material tooltip, I would like to include a button at the bottom right after the JSON data. When this button is clicked, it should open an Angular Material dialog. <ng ...

Retrieving data from a div container on an active website

Imagine having a website similar to , where you want to automatically retrieve the time value every second and save it in a .txt file. Initially, I considered using OCR (optical character recognition) software for this task, but soon realized that relying ...

Creating a custom npm package for a specific project

As I work on an npm package named my-library and regularly publish updates to a private npm repository, how can I efficiently test changes without repeatedly releasing new versions? Consider the following scenario: I tweak the code in my-library, but wan ...

Error: Unable to set value on Vuejs key - the target is read-only

Currently, I am utilizing a combination of Laravel9 with Vuejs3. In one of my blade views, I pass PHP variables to a Vue component like so: <subscription-form location="{{ $props['location'] }}" orientation="{{ $props['ori ...

Exploring the Depths: A Guide to Selecting Nodes in Java Based on Depth

In my current JSON representation, I have the following structure: { "total": "555", "offset": "555", "hasMore": "false", "results": [ { "associations": { "workflowIds": [], "companyIds": [], "ownerIds": [], ...

What causes useEffect to be triggered multiple times, even when it is dependent on another useEffect function that is being executed repeatedly?

I have a specific requirement that involves using two useEffect hooks. First useEffect is used to set the latitude and longitude in the state with an empty dependency array. useEffect(() => { navigator.geolocation.getCurrentPosition(geo = ...

Which child node of the html tag represents the "text"?

In my quest for answers, I have searched extensively but to no avail: As we all know, when a web page is loaded in a browser, it generates a tree-like structure called the Document Object Model (DOM). This allows Javascript to manipulate the elements of t ...

Sometimes, a record goes missing from a PHP/JSON array

When calling a PHP script to retrieve results and converting the array into a JavaScript array for a multiple choice quiz, I encountered an issue where certain records were missing unexpectedly. It seems to occur randomly as there is no specific pattern to ...

Decoding a JSON string array in PHP

When encoding data, I utilized the following code: $cont = json_encode(array_chunk($arr_content, 1, true)); The output of var_dump($cont) after encoding is: string(2670) "[[""],{"1":"Synonyms for good<\/b> at Thesaurus.com with free online th ...