将Json响应解释为纯文本 [英] Interpret Json response as plain text

查看:160
本文介绍了将Json响应解释为纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,我需要解析响应,根据我的理解,该响应实际上保存在变量"transferFlag"中

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

但是'transferFlag'会在

but 'transferFlag' alerts the whole ajax code while

我需要那个实际上返回方法值的ajax调用的响应

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

'getStudentIdsForTransfer'

'getStudentIdsForTransfer' ,

如何获得该方法的响应?

how to get the response of that method?

我是Ajax,Jquery和Jason的新手,这就是为什么在理解上有些麻烦.

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");

推荐答案

您很接近答案.. JSON 可以通过对象格式执行.这样您将获得正确的输出.是否要将json对象转换为字符串使用

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);

现在数据必须为字符串格式.将数据传递到html并进行迭代( JSTL ). Jstl是用于jsp页面中数据处理的最佳标记库

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

这篇关于将Json响应解释为纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆