Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7052105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:20:38+00:00 2026-05-28T03:20:38+00:00

I’ve seen the following example in the web to get a Json Product object

  • 0

I’ve seen the following example in the web to get a Json Product object into js from a WCF service:

function Product(ProductName, ProductDesc, Price, Quantity) {
    this.ProductName = ProductName;
    this.ProductDesc = ProductDesc;
    this.Price = Price;
    this.Quantity = Quantity;
}

function CallWCFService(WCFServiceURL) {
    $.ajax({
        type: "GET",
        url: WCFServiceURL,
        contentType: "application/json; charset=utf-8",
        dataType: 'json',
        processdata: true,
        success: function (msg) {
            WCFServiceSucceeded(msg);
        },
        error: WCFServiceFailed
    });
}

//On Successful WCF Service call 
function WCFServiceSucceeded(result) { 
    var productsArray = new Array(); 

    //Gets the Products 
    $.each(result, function (i, Product) { 
        productsArray[i]=Product; 
    }); 

    //Print all the product details 
    $.each(productsArray,function(i,Product) 
    { 
        alert(Product.ProductName + ' ' + Product.ProductDesc + ' ' + Product.Price + ' ' + Product.Quantity) 
    });
}

(original source)

Now, i cannot say what is really supposed to happen in here (my knowledge in javascript and jquery is scarily small), but i can say that i want to understand this snippet, in order to be able to modify it in order to contain a nested type, i.e: instead of ProductName we’ll have a list property from the WCF service response with its own fields.

Now, concretely, in this example, i don’t understand where is the Product function being called, it would seem to be that it is in here:

 //Gets the Products 
    $.each(result, function (i, Product) { 
        productsArray[i]=Product; 
    }); 

but to me it seems that is not clear if Product is there behaving as a declared parameter of the lambda that is being passed to $.each or if its actually invoking the ‘constructor’ call

Can you enlighten me on this code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:20:38+00:00Added an answer on May 28, 2026 at 3:20 am

    The Product function is never called. In fact, the code works perfectly fine without it. What’s happening is the JSON objects returned by the WCF call are in the exact same format or structure as the Product class (defined by the Product function).

    The each function takes an array and for each item in the array it executes the anonymous function supplied. The anonymous function has two parameters, i and Product. i is the index of the item in the array. Product is the name of the variable for the item passed in. At this point, the variable named Product has shadowed the Product function.

    The reason it appears that the items have been converted to a Product class is because the objects have the same structure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
i got an object with contents of html markup in it, for example: string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.