Ensure that the alert for an Ajax JSON record count remains active when the count is

Trying out Ajax JSON for the first time has been a bit tricky. Even though I hard coded "Record: 1" on the server side, it keeps alerting me with a total record of 0. I'm not sure where I went wrong. Could it be an issue with how I passed the array data? Strangely, no error messages are showing up. Any help would be appreciated. Thanks.

$.ajax({
        url: "CL0022_CHECK_GL_INDICATOR.asp",       
        method: "GET",
        dataType: "json",
        data: { 'arrGL':array.join('+++')},
        success: function (data) {


  alert(data.detail.Record)

            for(var i = 0; i < data.detail.Record; i++){

            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(errorThrown);
        }
    });

server side:

arrGL = Split(Request.Form("arrGL"),"+++")
arrLength = UBound(arrGL) + 1


Response.Write "{""detail"": {"
Response.Write """fields"": ["

For Each x In arrGL
    intcount = intcount + 1

    If intcount Mod 2 <> 0 Then 
        intcount2 = intcount2 + 1
        resetRst
        strSQL = " Select * from FLP003 Where ACCN='" & replace(x,"'","''") & "'"
        objRst.Open StrSQL,objConn
        If objRst.recordCount > 0 Then
            Response.Write "{""PSTIN"": """& trim(objRst.Fields("PSTIN"))&""","
            Response.Write """FSTAG"": """&trim(objRst.Fields("FSTAG"))&""","
            Response.Write """RECACI"": """&trim(objRst.Fields("RECACI"))&""","
        Else
            Response.Write "{""PSTIN"":"""","
            Response.Write """FSTAG"": """","
            Response.Write """RECACI"": """","
        End If
    Else
        Response.Write """LINE"": """& x &"""}"

        If arrLength <> intcount Then
            Response.Write ","
        End If
    End If
Next

Response.Write "],"
Response.Write """Record"": """& intcount2 &"""}}"

I found a solution by changing the method from GET to POST.

 $.ajax({
            url: "CL0022_CHECK_GL_INDICATOR.asp",       
            method: "POST",
            dataType: "json",
            data: { 'arrGL':array.join('+++')},
            success: function (data) {

   error: function (jqXHR, textStatus, errorThrown) {
            alert(errorThrown);
        }
    });

Answer №1

Make sure to include var obj = JSON.parse(data); before triggering the alert function. Give it a try and hopefully, it will resolve your issue. Additionally, you can test this code snippet as well:

alert(data.detail.Record.length);

Update 2

Consider implementing the following approach:

$.each(data.detail.fields,function(i){
    console.log(data.detail.fields[i].PSTIN);
});

Experiment with jQuery.each() method as it might provide a solution for your situation.

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

Tips for resetting the form input fields in Vue.js after the user has successfully submitted the form

I am facing an issue with my registration page. After the user enters some values and successfully submits the form, I want to clear all the fields. To achieve this, I am using a predefined function called reset() inside the script section. However, the ...

What is the best way to transform the request query id = ' [12eetftt76237,jhgasduyas7657] ' into an array of elements or strings like [12eetftt76237,jhgasduyas7657]?

Hey there, I am working on a project using hapijs and typescript. I have a requirement to send an array of IDs as parameters through the request URL. Here is an example of the URL: localhost:3444/?id='[askjajk78686,ajshd67868]' I attempted to u ...

Tomcat hosting a dynamic duo: Spring Boot and React!

Exploring the world of Spring Boot application development with a React client using Gradle is an exciting journey for me as I navigate through these new technologies. My current progress includes successfully creating a WAR file that encompasses several i ...

Test case does not treat similar content as similar

I've encountered an issue while working on a JsonExporter where the addition of JSON_PRETTY_PRINT has caused the testcase to fail unexpectedly. Even though there is no actual difference in the output, phpunit still detects a mismatch: // snippet from ...

I'm having trouble asynchronously adding a row to a table using the @angular/material:table schematic

Having trouble asynchronously adding rows using the @angular/material:table schematic. Despite calling this.table.renderRows(), the new rows are not displayed correctly. The "works" part is added to the table, reflecting in the paginator, but the asynchron ...

Having trouble setting the focus on a text box following a custom popup

Presenting a stylish message box and attempting to focus on a textbox afterward, however, it's not functioning as expected. Below is the HTML code: <a class="fancyTrigger" href="#TheFancybox"></a> <hr> <div id="TheFancybox">& ...

What is the best way to extract the class name from ui.item or event using the function(event, ui)?

Is there a way in jQuery to extract the class name from a function with two parameters, event and ui? For example, consider the following code snippet: $(document).tooltip({ show: null, position: { my: "left top", at: "left bottom ...

Avoid returning null and instead return object property in Flask-RESTful frameworks

In my hypothetical scenario, imagine having a table for clients containing fields such as id, name, and email. The email field is not required. The code snippet in question is as follows: client_fields = { 'id' : fields.String, 'name ...

The testing for React and TypeScript did not succeed. It is recommended to utilize the "jsdom" test environment for better results

I'm working on a basic React/TypeScript project and diving into the world of testing. I've opted for React Testing Library and Jest to test a straightforward product page that should display the message "Welcome to our product page." Unfortunate ...

Unable to retrieve missing form details due to an error in the Ajax call

I've encountered an issue with my ajax query, and I suspect there may be an error in the code. I expected to view missing details not entered in the signup form, but instead, I received a 500 server error and undefined $("#signupform") errors. Despit ...

Navigating the world of date pickers: a deceptively easy challenge

Take a look at this fiddle example to get started: http://jsfiddle.net/1ezos4ho/8/ The main goals are: When a date is selected, it should be dynamically added as the input value, like <input type text value="date selected".... Update: <s ...

Utilizing a JSON object passed from one JavaScript function to another: A comprehensive guide

After creating a function that returns JSON format through an ajax call, I received the following JSON data: { "communication": [{ "communication_name": "None", "communication_id": "1" }], "hardware": [{ "hardware_name ...

Utilizing Ajax data for CSS manipulation to display a live preview populated with form inputs

I am faced with a challenge involving a form containing approximately 80 input fields of type text and select. Each input field pertains to CSS values, and I aim to display a preview showcasing the new values (onChange any input value) in the form without ...

Using Selenium to interact with a Modal Dialog window

When trying to navigate to a page in IE9 using Selenium, a certificate error message appears on the page. By using AutoIT, I am able to click within the browser, TAB twice, and hit enter without any issues. However, after this step, an error for a "Modal d ...

Ways to access elements and their associated values in a JavaScript Array

I'm facing a challenge with a JavaScript array where I need to extract teams (Team A, Team B) and organize them into one array while preserving their order. See below for the current output of the array, as well as the JS code provided and the expecte ...

Tips on Selecting a Typed Value

When clicking on 'no_results_text' and it's not available in the list, I want to show the searched value from the alert. I have included an onclick method for 'no_results_text', so that the typed value is displayed in the alert. h ...

Rails implementation of AJAX pagination

Here is the jquery code I am using: $(function() { $(".pagination span.page a").click(function (){ $.get(this.href, null, alert("The pagination link was clicked" + this.href), "script"); return false; }); }); The alert pops up, confirming that ...

I'm having trouble figuring out why this React Router setup is not functioning properly. Can anyone provide any insights

As I delve into react routing practice, I've put together a geography-based web app. Starting off, I configured the router paths: import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import { BrowserRo ...

Utilizing Javascript to Parse Json Information

For my latest project, I am attempting to retrieve JSON data from a specific URL and display it on a web page using only JavaScript. This is all new to me. Can someone assist me in fetching the JSON data from the following link: I have been experimenting ...

What is the process for storing an array in AdonisJs migrations?

Having trouble saving an array into a PostgreSQL database! 'use strict' const Schema = use('Schema'); class UsersSchema extends Schema { up () { this.create('users', (table) => { table.increments(); t ...