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

  • SEARCH
  • Home
  • 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 9223679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:07:47+00:00 2026-06-18T04:07:47+00:00

This is what I know on the subject: We have an ajax function to

  • 0

This is what I know on the subject:

We have an ajax function to which we can pass an object with properties like this:

    var ajaxRequest = {};

    ajaxRequest['type'] = 'POST';
    ajaxRequest['async'] = false;
    ajaxRequest['datatype'] = 'json';
    ajaxRequest['url'] = '/Query/getMydata';

    $.ajax(ajaxRequest);

one of these properties is the data parameter which is made of key / value pairs:

    ajaxRequest['data'] = {color: 'red' , name: 'Steve' }

I tried to do something like this:

    var oData = [];
    oData['color'] = 'yellow';
    oData['name'] = 'Fred';

    ajaxRequest['data'] = oData;

but it does not work.

So my question is: there is an object that I can assign to the ‘data’ parameter, or I am forced to build the string with concatenation?

EDIT==============

Maybe I did not explain, I know that the method can be created by code like this:

     var ajaxRequest = {
      type: 'POST',
      async: false
      ....
      };

but I’m using objects and properties because I need to make the method ‘generic’, then I will add the ‘if’ like this:

    function ajaxReq(data){
         var ajaxRequest = {};

         if( !data.isEmpty()){
             ajaxRequest['data'] = data;
         }

           ajaxRequest['type'] = 'POST';
           ajaxRequest['async'] = false;
           ajaxRequest['datatype'] = 'json';
           ajaxRequest['url'] = '/Query/getMydata';

           ...

           $.ajax(ajaxRequest);
    }
  • 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-06-18T04:07:49+00:00Added an answer on June 18, 2026 at 4:07 am

    Your complex method is entirely unnecessary. You should just be using object literals:

    var ajaxRequest = {
        type: 'POST',
        async: false
        datatype: 'json',
        url: '/Query/getMydata'
    };
    
    $.ajax(ajaxRequest);
    

    You can also nest them, so you could have this:

    var ajaxRequest = {
        type: 'POST',
        async: false
        datatype: 'json',
        url: '/Query/getMydata',
        data: {
            color: 'yellow',
            name: 'Fred'
        }
    };
    

    jQuery will convert this into a query string for you, so you don’t need to worry about that.


    An additional clarification… The reason that oData = [] is causing problems is that [] creates an array. In Javascript, arrays are a special kind of object. Only properties with numeric keys are considered members of the array (e.g. oData[1]). If you’d used an object literal ({}) as you did with ajaxRequest, it would have worked fine.

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

Sidebar

Related Questions

Does anyone know if this is possible? I have a javascript which highlights the
I know this subject has been run into the ground, however I have tried
I know this subject has been discussed before but still have problem with refresh
I know this subject was discussed here, but I really can't get this to
I know this is a controversial subject and I know my reasons for wanting
I know this SO question, but it deals with the subject in more general
the only thing i know about this subject is... in PHP 5, when a
I know there are a lot of questions around on this subject, but I've
I'm curious to know what the community feels on this subject. I've recently come
I know this is possible in Perl, but I was wondering if this can

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.