Solved

how to make ajax call on click event

Posted on 2014-04-14
2
196 Views
Last Modified: 2014-04-28
is this the correct approach

 $( "#rights").click( function() {
	  alert("sanu");
	  $.ajax({
          type: "GET",
          dataType: "json",
          url: "/tile/mainRights.html",
      
          success: function(json,sttext,response) {
        	  
          }
          if(json != null && json.length > 0) {
        	  
        	  for(i = 0; i < json.length; i++) {
        	       var obj = json[i].code;
        	       var obj1 = json[i].descrip;

          
         }
});

Open in new window

0
Comment
Question by:roy_sanu
[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
2 Comments
 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 39998641
$( "#rights").click( function() {
 $.ajax({
                    type: 'GET', //or POST
                    url: 'WebForm1.aspx/MyMethod',
                    data: { },
                    dataType: 'json',
                    contentType: 'application/json; charset=utf-8',
                    success: function(data){
                            //do ur stuff here from data
                     }
                });
});
0
 
LVL 34

Accepted Solution

by:
Slick812 earned 250 total points
ID: 40018420
greetings roy_sanu, , you ask "is this the correct approach", and if you use the code you posted, I would say NO. The AJAX request in the setup has this -
      url: "/tile/mainRights.html"

but you set the dataType to "json"  I can not see a GET Ajax request to a .html page as having much possibility of sending back a CSV JSON string.

If you set the dataType to "json" , then There is ONLY one type of Ajax response allowed from the server (mainRights.html  in this case), and that's a properly formatted javascript Object Notation string using { } and [ ].

Also in the success: function( ) you expect an Object that has Many elements with "code" and "descrip" properties as code -
var obj = json[j].code;
var obj1 = json[j].descrip;

this may be awkward to handle depending on what you are trying to display on your updated page.

If you can describe what you need to do for your page update, and what you know that the server page  mainRights.html  will send back to AJAX, then we can see what is "the correct approach".
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

738 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