Solved

Jquery Ajax retun issue

Posted on 2013-06-14
3
263 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
Comment Utility
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
Comment Utility
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
Comment Utility
good
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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 the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 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