Solved

Jquery Ajax retun issue

Posted on 2013-06-14
3
268 Views
Last Modified: 2013-07-02
I'm not getting response as json type data from server.Please look into my code here...

    jQuery( "#dialog-form" ).dialog({
        autoOpen: false,
        height: 500,
        width: 750,
        modal: true,
        buttons :{
            "Search" : function(){
                jQuery.ajax({type : 'POST',
                dataType : 'json',
                   url : '<s:url action="part" method="list" />',
               success : handledata})
            }
        }
    });
    var handledata = function(data)
    {
        alert(data);
    }

if dataType = 'json' am not getting any response, but if didn't mention anything dataType, getting html format of page.

     public String list(){
     JSONObject jo = new JSONObject();
      try {
             Iterator it = findList.iterator();
                 while(it.hasNext()){
                 SearchResult part = (SearchResult) it.next();
                 jo.put("col1",part.getcol1());
                 jo.put("col2",part.getcol2());
                 
                 }
                 log.debug--------->:"+jo.toString());
          
        } catch (Exception e) {
          log.error(e);
                              }
        return jo.toString();
        }

Output format:

    {"col1":"col1","col2":"col2"}

I'm not getting data to jQuery success.
Please correct me, whats wrong here ?
0
Comment
Question by:Rose_Taylor
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 39250170
On your posted example you have:
url : '<s:url action="part" method="list" />',

I was expecting to see an actual url OR name of a server file here - ex:
url : 'myServerScript.php',

Also, I see:
...
  success:handledata
....

var handledata=function(data){...}

Open in new window


Notice that you are assigning the value of the variable handledata to success BEFORE you have even created the variable.  Thus, success is being assigned an undefined value.  

Try:
A.  Move up the definition so that handledata is defined BEFORE the line where you are making the ajax call:

var handledata=function(data){...}

jQuery( "#dialog-form" ).dialog({
...
});

Open in new window


OR
B.  Get rid of:
 var handledata = function(data)
    {
        alert(data);
    }

Open in new window

and instead change "success" to:
success : function (data)
              {
                alert(data);
              }

Open in new window


OR

C. change your definition of handledata so that it does not use the "var":
function handledata (data)
    {
        alert(data);
    }

Open in new window

0
 

Author Comment

by:Rose_Taylor
ID: 39250778
actually here search.jsp is the original file.but i have created popup window.so i have one more form in the same jsp file.
0
 

Author Closing Comment

by:Rose_Taylor
ID: 39295127
good
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Automatically open all pdf links in new tab 2 40
eclipse argument 14 53
jquery wizard next doesn't go to top of tab 4 53
JQuery Make Input Inactive based upon class value 2 26
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

867 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

21 Experts available now in Live!

Get 1:1 Help Now