Javascript 调用JS文件时从JQuery Ajax调用检索参数
我试图使用jQueryAjax调用javascript文件。我需要向它传递一些参数,但我不确定在使用javascript时如何传递(PHP似乎更简单)。这是我的电话:Javascript 调用JS文件时从JQuery Ajax调用检索参数,javascript,jquery,parameters,parameter-passing,Javascript,Jquery,Parameters,Parameter Passing,我试图使用jQueryAjax调用javascript文件。我需要向它传递一些参数,但我不确定在使用javascript时如何传递(PHP似乎更简单)。这是我的电话: function getDocument(parameters) { $.ajax({ type: "GET", url: "js/document.js", dataType: "script", data: "in
function getDocument(parameters) {
$.ajax({
type: "GET",
url: "js/document.js",
dataType: "script",
data: "info=hellothere",
success: function(msg) {
},
error: function(jqXHR, textStatus, errorThrown){
}
});
}
我只想打印document.js中参数'info'的内容
所以本质上是应该打印“hellothere”。您最好使用PHP 将URL更改为
document.php
,并在该文件中执行以下操作:
echo $_GET['info'];
应该是服务器文件的路径
无法使用ajax请求将ajax请求发送到.js文件
将请求发送到.php文件,并在其中编写处理数据的方法
Ajax请求主要用于将数据从客户端发送到服务器端
如果要访问两个.js文件之间的数据,最好将该数据存储在cookie
或本地存储中
url: "js/document.js"