简体   繁体   English

在ajax调用中发送全局变量

[英]sending global variable in ajax call

I have set a global variable from the data coming from a jquery. 我已经从来自jQuery的数据中设置了一个全局变量。 and save that data in a global variable as : 并将该数据保存为以下全局变量:

 var window.globalname = data;  // variable value set in another ajax call

i want to send this global variable through another ajax call then how should i write ?? 我想通过另一个ajax调用发送此全局变量,那我应该怎么写?
i have written : 我已经写了 :

type:'POST', // ajax call
url:'url'
data: {name="globalname"} or data :{name="$globalname"} 

i want to know how to write this data ?? 我想知道如何写这些数据?

First of all, (almost) NEVER use global variables in JavaScript. 首先,(几乎)永远不要在JavaScript中使用全局变量。 You pollute your global scope. 您污染了您的全球范围。

As to your question, try the following: 关于您的问题,请尝试以下操作:

$.ajax({
  type: 'POST',
  url: 'url',
  data: {name: window.globalname},
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM