Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

jquery/ajax to code behind

I have below object called resultObj  from jquery,
how can I pass to code behind c#?

  $.ajax({
                cache: false,
                type: "GET",
                async: false,
                dataType: "json",
                contentType: 'text/plain',
                url: GetDealerList + encodeURIComponent("(06234,'1111,asdfasdfasd,asdfasfasdf')"),
                success: function (data) {
                    $('#data').html(data);
                    alert(data);
                    if (data == null)
                        return;
                    resultObj = jQuery.parseJSON(data);
                    if (resultObj.Status != 'Failed') {
                        $('#json').html(createDealer(resultObj.Data));
                    }
                },
                error: function (xhr) {
                    $('#data').html(xhr.responseText);
                    //alert(xhr.responseText);

                }
            });
0
ITsolutionWizard
Asked:
ITsolutionWizard
  • 4
  • 3
1 Solution
 
RobOwner (Aidellio)Commented:
As described here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify use JSON.stringify to covert the js object to JSON format.  Then include that in your ajax request.
0
 
ITsolutionWizardAuthor Commented:
I need some sample codes to support what you mentioned....Thanks
0
 
RobOwner (Aidellio)Commented:
url: GetDealerList + encodeURIComponent(JSON.stringify(resultObj)),
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ITsolutionWizardAuthor Commented:
inside of code behind. how can i capture it?
0
 
RobOwner (Aidellio)Commented:
The querystring will be sent and made available to your webmethod. I'm not familiar with .net but usually done with the Request class
0
 
ITsolutionWizardAuthor Commented:
Not sure which property should be used from request.
0
 
RobOwner (Aidellio)Commented:
like this, you need to add the data attribute to your ajax call.  Then the variable "result" will be available via the Request['result']

 $.ajax({
                cache: false,
                type: "GET",
                async: false,
                dataType: "json",
                contentType: 'text/plain',
               data: {
                       "result": encodeURIComponent(JSON.stringify(resultObj))
                },
               url: GetDealerList,
                success: function (data) {
                    $('#data').html(data);
                    alert(data);
                    if (data == null)
                        return;
                    resultObj = jQuery.parseJSON(data);
                    if (resultObj.Status != 'Failed') {
                        $('#json').html(createDealer(resultObj.Data));
                    }
                },
                error: function (xhr) {
                    $('#data').html(xhr.responseText);
                    //alert(xhr.responseText);

                }
            });
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now