使用Ajax加载JavaScript并向其传输数据(如php脚本) [英] Load with Ajax a javascript and transmit data to it as to a php script

查看:55
本文介绍了使用Ajax加载JavaScript并向其传输数据(如php脚本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在像这样加载我的脚本:

I am loading my script like this:

var myTestString = "/modules/admin";
$.ajax({
type: "GET",
url: "../../includes/test_tooltip.js",
data: "module="+myTestString,
dataType: "script"
});



是否可以像这样访问我的test_tooltip.js中的模块变量?

我也在我的主要js文件中尝试过此操作:



Is it possible to have access to module variable in my test_tooltip.js like this?

I tried this as well in my main js file:

var myTestString = "/modules/admin";
$.ajax({
type: "GET",
url: "../../includes/test_tooltip.js",
data: { module: myTestString },
dataType: "script"
});



而在test_tooltip.js中:



And in test_tooltip.js this:

console.log("I am loaded!" + data.module);



我的情况就是这样.有时,我有时需要加载该javascript,然后在不同的模块中进行加载,并且我需要此javascript来知道哪个模块,因为他将不得不基于该模块执行一些请求.

在php中,我知道您可以使用$ _REQUEST ["module"]访问数据,如果可以在javascript中完成,则效果会很好.
对不起,英语不好.

现在要使其正常工作,我使用



My scenario is like this. I sometimes need to load that javascript and when i do, i do it in different modules, and i need this javascript to know which module because he will have to do some requests based on the module.

In php i know you can acces data with $_REQUEST["module"], if it could be done in javascript similar would be great.
I am sorry for poor english.

Right now to make it work i use

window.variable

delete window.variable

推荐答案

. ajax({ 类型:" , 网址:" , 数据:" + myTestString, dataType:" });
.ajax({ type: "GET", url: "../../includes/test_tooltip.js", data: "module="+myTestString, dataType: "script" });



是否可以像这样访问我的test_tooltip.js中的模块变量?

我也在我的主要js文件中尝试过此操作:



Is it possible to have access to module variable in my test_tooltip.js like this?

I tried this as well in my main js file:

var myTestString = "/modules/admin";


.ajax({ 类型:" , 网址:" , 数据:{模块:myTestString}, dataType:" });
.ajax({ type: "GET", url: "../../includes/test_tooltip.js", data: { module: myTestString }, dataType: "script" });



而在test_tooltip.js中:



And in test_tooltip.js this:

console.log("I am loaded!" + data.module);



我的情况就是这样.有时,我有时需要加载该javascript,然后在不同的模块中进行加载,并且我需要此javascript来知道哪个模块,因为他将不得不基于该模块执行一些请求.

在php中,我知道您可以使用



My scenario is like this. I sometimes need to load that javascript and when i do, i do it in different modules, and i need this javascript to know which module because he will have to do some requests based on the module.

In php i know you can acces data with


_REQUEST ["module"]访问数据,如果可以用javascript来完成,则效果很好.
对不起,英语不好.

现在要使其正常工作,我使用
_REQUEST["module"], if it could be done in javascript similar would be great.
I am sorry for poor english.

Right now to make it work i use
window.variable

delete window.variable


这篇关于使用Ajax加载JavaScript并向其传输数据(如php脚本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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