我正在尝试利用 JQuery Ajax 来调用 javascript 文件。我需要向它传递一些参数,但我不确定在使用 javascript 时如何传递(PHP 似乎更简单)。这是我的电话:
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'];
关于javascript - 调用 JS 文件时从 JQuery Ajax 调用中检索参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13033892/