如何将变量数据成功存储到全局变量ajax(并在另一个函数中调用它)

时间:2021-09-10 14:04:20

Here is my code.

这是我的代码。

<head>
<script>
var myGlobal ={};
</script>
</head>

<body>

$(function ()

 { 

 $.ajax({  
      url: 'test.php',                      
      data: "",
      dataType: 'json',                   
      success: function(data)
      {
        var vname = data.name; 
        my_global.push(data.name);
      }


alert('The user selected: ' + my_global.newval); // i will use this value(vname value)

I would like to use VNAME value in other function..

我想在其他函数中使用VNAME值..

1 个解决方案

#1


Put all the code in the same script tags. What you wrote won't even work. The ajax code will just be displayed as text and not handled as script.

将所有代码放在相同的脚本标记中。你写的东西甚至都不起作用。 ajax代码将仅显示为文本而不作为脚本处理。

#1


Put all the code in the same script tags. What you wrote won't even work. The ajax code will just be displayed as text and not handled as script.

将所有代码放在相同的脚本标记中。你写的东西甚至都不起作用。 ajax代码将仅显示为文本而不作为脚本处理。