Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jquery ajax get返回302的过程中为API执行PHP重定向_Php_Jquery_Ajax_Redirect - Fatal编程技术网

在jquery ajax get返回302的过程中为API执行PHP重定向

在jquery ajax get返回302的过程中为API执行PHP重定向,php,jquery,ajax,redirect,Php,Jquery,Ajax,Redirect,我通过jqueryajax调用一个php页面,它连接到一个API,获取请求令牌,执行头重定向回到同一页面,然后返回一个json编码的字符串。但是,它返回一个302错误 我的问题是,如何实现它才能正常工作?这里我提供了一个包含2个文件的基本示例 index.html <html> <head> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script

我通过
jqueryajax
调用一个php页面,它连接到一个API,获取请求令牌,执行头重定向回到同一页面,然后返回一个json编码的字符串。但是,它返回一个302错误


我的问题是,如何实现它才能正常工作?

这里我提供了一个包含2个文件的基本示例

index.html

<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript">
    var param = 'name=YourName';
    var request = $.ajax({
        url: "phpcallback.php",
        type: "POST",
        data: param,
        dataType: "json"
    });     
    request.done(function(response) {       
        $("#Mydiv").html(response); 
    });
</script>
</head>
<body>
<div id="Mydiv">
Click to get json response from server
</div>
</body>
</html>

var param='name=YourName';
var请求=$.ajax({
url:“phpcallback.php”,
类型:“POST”,
数据:param,
数据类型:“json”
});     
请求.完成(函数(响应){
$(“#Mydiv”).html(回复);
});
单击以从服务器获取json响应
phpcallback.php

<?php
  $Name = $_POST['name'];
  $Arr = array();
  $cn = mysql_connect("localhost","root","");
  mysql_select_db("mydb", $cn);
  $Query = mysql_query("select * from mytable where name = '$Name'",$cn);
  $Row = mysql_fetch_array($Query);     
  $Arr = array('Null');     
  $Arr = array($Row['Name'],$Row['Email'],$Row['Address'],$Row['Phone']);   
  echo json_encode($Arr);   
?>

如果您有相应的数据库设置,此代码应该可以工作

问候

伊曼纽尔·保罗

首先提供大量额外信息。这对你来说似乎很明显,但我们一开始对你正在做的事情一无所知。