Solved

jquery/ajax to code behind

Posted on 2015-02-06
7
158 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
  • 4
  • 3
7 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
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
 

Author Comment

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

Expert Comment

by:Rob Jurd, EE MVE
ID: 40595180
url: GetDealerList + encodeURIComponent(JSON.stringify(resultObj)),
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

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

Expert Comment

by:Rob Jurd, EE MVE
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
 

Author Comment

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

Accepted Solution

by:
Rob Jurd, EE MVE 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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…
The goal of this video is to provide viewers with basic examples to understand and use pointers 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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now