douyun8885 2015-10-23 11:37
浏览 73

如果我从另一个装有ajax的php文件调用php文件,我会收到错误

Like the title says, I'm doing an ajax call to a php file like this:

function loadForm(val1, val2, val3){
    $.ajax({

        url : 'AL_loadForm.php',
        type : 'POST',
        data : {
            value1 :val1,
            value2: val2,
            value3:val3
        },
        dataType:'json',
        success : function(data) {              
            alert(data);
        },
        error : function(request,error)
        {
            alert("error");
        }
    });
}

And in my loadForm.php I've got two cases, If I load this code I got a successful ajax call without error:

<?php 
if($_POST){


    $var1 = $_POST['value1'];
    $var2 = $_POST['value2'];
    $var3 = $_POST['value3'];
    echo json_encode($var1);
}
?>

But if I load this same code with an include php file I get an error in my ajax call

 <?php 
    if($_POST){

        include 'AL_createTbObj.php';
        $var1 = $_POST['value1'];
        $var2 = $_POST['value2'];
        $var3 = $_POST['value3'];
        echo json_encode($var1);
    }

Is this normal? can't do stuff in another php files with a single ajax call??

EDIT: to add content of AL_createTBObj.php, basically it creates an object from the class tableRows.php

<?php
     require 'tableRows.php';

        //Create mySqli object with DB Params
        $conn = new mysqli($dbHost, $dbUser, $dbPass, $dbDB);
        //Create TableRows object
        $tb = new TableRows($conn);
        //Connect to Data Base
        $tb->checkDb();
?>

There is some echo 'content'.. in the class tableRows.php but those methods aren't called yet....

  • 写回答

2条回答 默认 最新

  • dsa88886666 2015-10-23 12:19
    关注

    Your AL_createTBObj.php file is missing the <?php at the top. This means that the contents will be returned as text instead of being handled as php.

    Check this and any other included files have the <?php before any code - at the very top of the file if it's all php. You do not need to terminate files with the ?> and you may choose to leave it out as this has the advantage of ensuring no whitespace at the end of the file after the ?> is sent to the client.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用