Solved

Jquery Ajax retun issue

Posted on 2013-06-14
3
272 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 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
pass foreach data in php into jquery ajax 10 72
Geolocation works...sometimes 2 34
How to strip HTML from this JS code using regex 29 39
Ajax success not firing alert 6 36
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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…

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