Solved

jquery/ajax to code behind

Posted on 2015-02-06
7
171 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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 500 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays 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.
Suggested Courses

632 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