如何解析HTTP响应文本中的字符串 [英] How to parse strings in HTTP response text

查看:153
本文介绍了如何解析HTTP响应文本中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在解析Ajax请求发送的HTTP响应中的一些字段,但我无法获得正确的值。



键值

----------------------

my_ID一个

ID两个



当我尝试获取ID值时,我的函数返回my_ID值。

我使用了以下代码。

Hi,

I am parsing some fields from HTTP response sent by Ajax request but I am unable to get the proper value.

Key value
----------------------
my_ID One
ID Two

when I am trying to fetch value of ID only my function return me value of my_ID.
I have used following code.

myFunction(httpresponse,param)
{
    var val;
    if(httpresponse.match(param))
    {
      //Here it matches the ID with my_ID and return the value.
    }
}
    {





}





}

document.getElementById("ID").innerHTML=myFuntion(xmlhttp.responseText,"ID");

xmlhttp.responseText contains the data for both ID and my_ID field.





请建议如何处理。



Pls suggest how to handle this.

推荐答案

我认为你可以得到回应是{my_ID:一个,ID:两个}你需要ID值

获取准确的输出更新myFunction如下:



函数myFunction(httpresponse,param){

return jsonresponse.param;

}



以上细节对于json单曲记有效。
I think you can get response is { "my_ID":"One","ID":"TWO" } and you need value of "ID"
For getting exact output update "myFunction" like below :

function myFunction(httpresponse,param){
return jsonresponse.param;
}

above details are valid for json single record.


这篇关于如何解析HTTP响应文本中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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