我创建了一个使用两个参数的PHP脚本functionexchangeRate($exchangeFrom, $exchangeTo)
。
我试图用Jquery的$ .get函数调用这个PHP脚本,但我无法弄清楚如何发送这两个参数(我感觉像火鸡 - 双关语意图)。
var getRate = $.get('exchangeRate.php', function(data){
});
答案 0 :(得分:3)
你必须使用回调,或同步调用它:
$.get("exchangeRate.php", {exchangeFrom:"what",exchangeTo:"ever"},function(resp){
alert(resp);
//resp is what your page returns!
//find getRate in resp and use it here
});
要使事情同步,你需要像
这样的东西$.ajaxSetup({
async: false,
});
var getRate = null;
$.get("exchangeRate.php", {exchangeFrom:"what",exchangeTo:"ever"},function(resp){
alert(resp);
//resp is what your page returns!
//find getRate in resp
getRate = something;
});
//use getRate here
另外,我猜你的PHP是正确的,类似
<?php
function exchangeRate($exchangeFrom, $exchangeTo){...}
echo exchangeRate($_GET["exchangeFrom"], $_GET["exchangeTo"]);
?>
答案 1 :(得分:1)
试
var getRate = $.get('exchangeRate.php', {param1:"val", param2:"val2"}, function(data){
});
或
var getRate = $.get('exchangeRate.php?param1=val¶m2=val2', function(data){
});