JQuery $.get or $.ajax call PHP script on server that requires 2 parameters
I have created a PHP script functionexchangeRate($exchangeFrom, $exchangeTo)
that uses uses two parameters.
I am trying to call this PHP script with Jquery's开发者_JAVA百科 $.get function but I can not figure out how to send the two parameters (I feel like a turkey - pun intended).
var getRate = $.get('exchangeRate.php', function(data){
});
you have to use a callback, or call it synchronously:
$.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
});
to make things synchronous you need something like
$.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
Also, I guess your PHP is right, with something like
<?php
function exchangeRate($exchangeFrom, $exchangeTo){...}
echo exchangeRate($_GET["exchangeFrom"], $_GET["exchangeTo"]);
?>
try
var getRate = $.get('exchangeRate.php', {param1:"val", param2:"val2"}, function(data){
});
or
var getRate = $.get('exchangeRate.php?param1=val¶m2=val2', function(data){
});
精彩评论