Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

jquery/ajax to code behind

Posted on 2015-02-06
7
Medium Priority
?
172 Views
Last Modified: 2015-03-12
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
Comment
Question by:ITsolutionWizard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 43

Expert Comment

by:Rob
ID: 40595101
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
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40595174
I need some sample codes to support what you mentioned....Thanks
0
 
LVL 43

Expert Comment

by:Rob
ID: 40595180
url: GetDealerList + encodeURIComponent(JSON.stringify(resultObj)),
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40600044
inside of code behind. how can i capture it?
0
 
LVL 43

Expert Comment

by:Rob
ID: 40600437
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
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40600807
Not sure which property should be used from request.
0
 
LVL 43

Accepted Solution

by:
Rob earned 2000 total points
ID: 40602224
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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question