在 php 上使用 ajax 返回值
Use ajax return value on php
我正在尝试将ajax响应值传递给php函数。
阿贾克斯.js
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
var a = xmlhttp.responseText;
}
}
我需要a
值用于PHP函数。
测试.php
function testFun($a);
这可能吗???感谢您的帮助!!
Try This:
/** JAVA SCRIPT **/
// create a request query
var queryString = "?send_param=" + a;
// send request query to php file
xmlhttp.open("GET", "test.php" + queryString, true);
xmlhttp.send(null);
/** JAVA SCRIPT END **/
/** PHP SCRIPT **/
[ test.php ]
<?php
// if $_REQUEST array is empty show error and die;
if (empty($_REQUEST)) {
die("Error: No request found");
} else {
// split the $_REQUEST array and make array key as php variable
extract($_REQUEST);
}
/**
* Function testFun
* @param string $a
*/
function testFun($a)
{
// return val
}
// Call the function
testFun($send_param);
?>
/** PHP SCRIPT END **/
I preferred to use $.ajax function instead to Java Script Ajax, Coz it's handy :) and to good.
[1]: http://php.net/manual/en/function.extract.php
编写另一个 AJAX 请求并将a
传递到包含该函数的 PHP 文件中,并将输入读取为 GET 或 POST,然后根据需要使用输出。使用像jQuery这样的JS框架将有助于缩短AJAX调用。
相关文章:
- 从Ajax函数返回值
- 使用Javascript数组或JSON来存储AJAX请求的返回值,以备将来使用
- jQuery 延迟的 AJAX 调用返回值
- 如何使用 AJAX 返回 JS 值
- 我需要从ajax返回值
- AJAX没有从JSP返回值
- 如何从Ajax请求中获取返回值并将其分配到元素中
- 如果我使用html表单(而不是ajax),则获取服务器的响应代码或返回值
- 使用ajax和回调函数向函数传递值/从函数返回值
- 在 php 上使用 ajax 返回值
- 如何验证 ajax 返回值的 javascript “not null”
- 函数的Ajax返回值
- Ajax返回值不工作
- Javascript确实用户存在,从ajax返回值到后期
- jQuery AJAX.返回值未定义
- 如何读取ajax返回值的responseText
- 如何从ajax返回值
- 如何检查ajax返回值
- 从 ajax 返回值,回到它的 JS 函数
- 如何在函数调用中使用ajax返回值