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

What is the process for importing Buffer into a Quasar app that is using Vite as the build tool

I'm having issues with integrating the eth-crypto module into my Quasar app that utilizes Vite. The errors I'm encountering are related to the absence of the Buffer object, which is expected since it's typically found in the front end. Is ...

Intermittent issue with Webdriver executeScript failing to detect dynamically created elements

It has taken me quite a while to come to terms with this, and I am still facing difficulties. My goal is to access dynamically generated elements on a web page using JavaScript injection through Selenium WebDriver. For instance: String hasclass = js.exec ...

Modifying the value of an animated status bar using the same class but different section

I need the status bars to work individually for each one. It would be great if the buttons also worked accordingly. I have been trying to access the value of "data-bar" without success (the script is able to process the "data-max"). However, the script see ...

The issue of Ajax failing to execute an HTTP POST request in an HTML environment

I am creating a sample HTML code that involves making HTTP post requests using an Ajax function. The task at hand is to execute 2 HTTP POST requests and 1 GET request sequentially based on the correct response received. POST: URL: http://localhost:8082 ...

The functionality of Ajax is not supported on iPhone Safari browsers

I have encountered an issue where my ajax function works perfectly in Firefox, but it fails to work on my iPhone. Initially, I suspected the XMLHttpRequest was causing the problem, but that does not appear to be the case. I can confirm that the PHP script ...

Google Maps API now offers the ability to generate directions with up to 500 waypoints

I am facing a challenge with displaying a route on Google Maps using an array of 500 waypoints extracted from a GPS route. Google Maps is unable to create a direction or route with more than 23 waypoints, making it difficult to replicate the original GPS ...

Tips for leveraging async and await within actions on google and API integration

Currently, I am developing an Actions on Google project that utilizes an API. To handle the API calls, I am using request promise for implementation. Upon testing the API call, I observed that it takes approximately 0.5 seconds to retrieve the data. Theref ...

Tips for transferring information from an express rendering to a Vue component?

When working with an express route, page.js router.post('/results', (req, res, next) => { output.terms = "hello" output.results = [{"text": "hello world"}, {"text": "hello sunshine"}] res.render("/myview",output) }) The cod ...

Having trouble retrieving the latest value of a scope variable when dealing with multiple partial HTML files controlled by a single Angular controller

In my Angular controller, I have an HTML file that includes two partials. Here is a simplified version: HTML: <!DOCTYPE html> <html> <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> ...

The addition of an asynchronous call caused Array.map to start experiencing errors

I am working on a React component that iterates through an array of messages and renders JSX based on certain conditions: messages.map(async (msg) => { let previewImage: URL | undefined = undefined; if (msg.mediaId) { previewImage = await stora ...

Guide on calculating the quantity of rows in a Json data set

How can I determine the number of rows where my ID is present in one of the fields, which are stored as JSON objects: { "Monday":{"1":"15","2":"27","3":"74","4":"47","5":"42","6":"53"}, "Tuesday":{"1":"11","2":"28","3":"68","4":"48","5":"43","6":"82"} ...

"Transforming JSON data into structured key-value pairs using JavaScript

Develop a function named "json_filter" that accepts a JSON-formatted string as input. The accepted format is an array of objects, where each object contains keys for "mass," "density," "temperature," and "velocity," each mapped to a floating-point number. ...

"Executing the command 'npm run dev' is successful, however, the command 'next dev' does not yield the expected result

Trying out Next for the first time using npx create-next-app, but running into issues with the scripts. While npm run dev works without any problems, executing next dev gives me an error saying zsh: command not found: next. Any idea why this is happening? ...

Encountering an Unexpected Token Error while using Jest in Next.js for node-modules

After setting up my Next.js project, I decided to install jest by running the command below: npm i --save-dev jest @testing-library/react @testing-library/jest-dom jest-environment-jsdom I then created a jest.config.json file with the following code snipp ...

Having trouble downloading files in React and Node.js

I need to retrieve a specific file from the uploads folder and download it into my download folder. Both folders are located in the same directory, and the file's name is BasicUserFile-id.jpg. On my second attempt, I tried hardcoding the file name bu ...

AngularJS confirmation directive for deleting items

I am currently utilizing this directive for a confirmation prompt when deleting an app. However, regardless of whether I click cancel or yes, the app still gets deleted. <small class="btn" ng-click="delete_app(app.app_id)" ng-show="app.app_id" ng-con ...

Terminate all dormant MySQL pool connections using Node.js

In my project involving node.js and connection pooling, I have noticed that despite releasing connections after each query as shown below: return new Promise((resolve, reject) => { sql.getConnection(function (err, conn) { if (err) { ...

Using an ng-repeat directive alongside an if condition in Angular

My website contains a vast array of 30 articles, previously represented by around 300 lines of HTML code, but now condensed to just 10 lines with angularjs. However, certain articles hold special significance and require specific display criteria. Check ou ...

Pass on the touchmove event from the panel to the content using jQueryMobile

Within my interface, I have a link labeled myLink located in a side panel labeled myPanel, along with some content labeled myContent. My goal is to: Tap and hold on the link myLink within the panel myPanel Have the panel myPanel close immediately Add an ...

Issue with ngFor displaying only the second item in the array

There are supposed to be two editable input fields for each section, with corresponding data. However, only the second JSON from the sample is being displayed in both sections. The JSON in the TypeScript file appears as follows: this.sample = [ { "se ...