JavaScript not running on jsfiddle.net

后端 未结 4 1124
无人共我
无人共我 2020-11-22 09:42

The code below works on a live site but I can\'t get it to run on the site jsfiddle .

See this for example.

Can anyone tell me why it\'s not working on jsfid

4条回答
  •  青春惊慌失措
    2020-11-22 09:48

    Look at:

    https://stackoverflow.com/a/4935684/6796393

    Or it is better to see this one:

    https://stackoverflow.com/a/19110630/6796393

    Here is what I tested:

    function testJSON() { 
        var jsonString = '{"param1":"123","param2":"XXX78","param3":"11378"}'; 
        var tmp_obj = eval('(' + jsonString + ')');
        document.getElementById("result").innerHTML =  tmp_obj.param2;
    }
    

    and

    function testJSON() { 
        var jsonString = '{"param1":"123","param2":"XXX78","param3":"11378"}'; 
        var tmp_obj = JSON.parse(jsonString);
        document.getElementById("result").innerHTML =  tmp_obj.param2;
    } 
    

    It is better to use the second aproach.

    P.S.> I came from How to parse parameters from JSON String using JS?

提交回复
热议问题