2

I have following piece of code and I need to parse the response which according to my understanding actually saves in variable 'transferFlag'

but 'transferFlag' alerts the whole ajax code while

I need the response of that ajax call which is actually returning the value of method

'getStudentIdsForTransfer' ,

how to get the response of that method?

I am new to Ajax, Jquery, Jason that is why having some trouble in understanding.

  var transferFlag=({
                    url: "UtilBean/getStudentIdsForTransfer",
                    handleAs: 'text',
                    data:
                    {   
                        studentId: this.studentId                       
                    },
                    contentType: "application/json; charset=utf-8",
                    success: function(data) { var myValue = data.myValue; },

                    failure: function() { alert("Uh oh"); }
                  });
            alert(transferFlag.toString()+ ".... Hi transfer Flag");
Just_another_developer
  • 5,737
  • 12
  • 50
  • 83

2 Answers2

2

You are close to the answer..Every operations in javascript on JSON can performed through object format. So you are getting the correct output. Do you want to convert json object in to string use

var data = JSON.stringify(jsonObject);

Now the data must be in the string format. Pass the data to html and iterate(JSTL). Jstl is the best tag lib for data manipulation in jsp pages

Aravind Cheekkallur
  • 3,157
  • 6
  • 27
  • 41
1

You can use JavaScript Native Function. JSON.stringify(transferFlag)

Edit Part Answer: Use the Proper Ajax call from jquery Example.wrote Your code in Sucess: callback Method.and then JSON.stringify(data)

Adnan
  • 179
  • 7
  • Got it , thank you but it alerts the whole piece of code that I wrote above while I need response of that ajax call, how to get the response? – Just_another_developer May 29 '14 at 06:28
  • @HappyDev Well, you have to *use* an AJAX call .. but that's a different task/question. Also, you only want to serialize ("stringify") the *data* in the AJAX payload (at the appropriate level), not all the properties used for the AJAX call. I recommend reading a tutorial. – user2864740 May 29 '14 at 06:30
  • @HappyDev you can Do same think in you success callback method.if you want to get data from success: write your code in success:. – Adnan May 29 '14 at 06:35
  • I am using alert in success method but it doesnt show up niether in failure. is the above piece of code has some mistake? – Just_another_developer May 29 '14 at 06:41
  • @HappyDev Yes Goto example that i post in my answer and grab Ajax code from there. – Adnan May 29 '14 at 06:47