我尝试使用Jquery,使用load函数,调用url并得到结果
首先我使用这个简单的 php 代码,从 url 调用并使用 Jquery 加载,该文件的名称为 test.php :
<?php
if ($_REQUEST['send_test']=="ok")
{
$result="fine";
}
?>
另一方面,我在index.php中有Jquery脚本,用于调用test.php:
<div id="loader"></div>
<script>
jQuery(document).ready(function() {
jQuery("#loader").load("test.php?send_test=ok");
/// Here the question ///
if($result=="fine")
{
alert("Value it´s Fine");
}
else
{
alert("Value Different");
}
/// Here it´s the central question, how get this, i know, sure bad writte but put, for people understand what i need
});
</script>
在这个小脚本中,使用 Jquery,我尝试在调用 test.php 时从加载中获取结果,这是我放在这里的第一个代码,但就我而言,我不知道我必须怎么做,才能获取“$result"值,用于 Jquery 脚本内
这是我的问题,我希望理解我,提前谢谢
最佳答案
我建议您查看$.get()
。这是一个例子。
jQuery(function($) {
$.get("test.php", {
send_test: "ok"
}, function(result) {
console.log(result);
if (result == "fine") {
alert("Value is Fine");
} else {
alert("Value is Different");
}
});
});
关于javascript - Jquery 加载并获取字符串结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60729659/