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 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块