weixin_33708432 2015-03-26 00:16 采纳率: 0%
浏览 38

加载时执行php文件

I have a PHP file create_json.php that creates a json file from a table in my database i want my app to load that file in order to recreate the json file every time i start it

here is what i tried to do

<script language="javascript" type="text/javascript">

    window.onload = function(){  

           $.ajax({

                type: "GET",

                url: "create_json.php" ,

                success : function() { 

                   alert("created");

                }

            }).error(function(){

            alert('error... ohh no!');

          });

        }

</script>

I have no error i get the "created alert but the file is not created and i'm sure that my create_json.php file works it works perfectly when i execute it on a browser it just dont work on my app help please here is the php file content

$conn= mysqli_connect("localhost","root","") or die ("could not connect to     mysql"); 

mysqli_select_db($conn,"bd") or die ("no database");   

$sql=mysqli_query($conn,"select * from user"); 

$response = array();
$user = array();
$result=$sql;

while($row=mysqli_fetch_array($result)) 
{ 
$email=$row['email']; 
$mdp=$row['mdp']; 

$user[] = array('email'=> $email, 'mdp'=> $mdp);

} 

$response['user'] = $user;

$fp = fopen('C:\Users\Oussemat\Documents\PFE11\wwwesults.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);



?> 
  • 写回答

1条回答 默认 最新

  • weixin_33749242 2015-03-26 09:22
    关注

    Try the following script.

    <script language="javascript" type="text/javascript">
    
        $(document).ready(function(){
    
               $.ajax({
    
                    type: "GET",
    
                    url: "create_json.php" ,
    
                    success : function() { 
    
                       alert("created");
    
                    }
    
                }).error(function(){
    
                alert('error... ohh no!');
    
              });
    
            });  
    
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度