Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Jquery Ajax retun issue

Posted on 2013-06-14
3
Medium Priority
?
293 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
[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
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 1500 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
A solution for Fortify Path Manipulation.
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

618 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