简体   繁体   中英

Why is JQuery Ajax returning successfully but showing an error in firebug in PHP app?

I have a form which when submitted is checked by the JQuery validator plugin. This works fine. In the JQuery code though I have my submit handler. This part looks like the following:

submitHandler: function (form) {
     $.ajax({
         type: "POST",
         url: "php/main.php",
         data: $(form).serialize()
     });
     return false;
 }

Now I dont see anything wrong with this, looks fine to me. Then in main.php, I simply do

<?php
var_dump("OK");
include("APIEmailConnection.php");
var_dump("OK2");

if (isset($_POST["emailAddress"]) && !empty($_POST["emailAddress"])){
    var_dump("OK3");
    $connection = new APIEmailConnection();
    $connection->obtainConnection();
    var_dump("OK4");
}

I dont show it above, but I have a success function in my ajax call, and everytime I submit my form with an email address the success is fired. However, if I check firebug, I see the error

Fatal error: Class 'APIEmailConnection' not found in /var/www/vhosts/myurl.com/httpdocs/folder/php/main.php on line 12

Also, the outputs from my var_dumps are

string(2) "OK"
string(3) "OK2"
string(3) "OK3"

So its missing OK4. My folder structure is like so

index.html
    --js
        --main.js
    --php
        --main.php
        --APIEmailConnection.php

Now php include should be relative to the current file location, and because I am in main.php I believe my include is the correct path. And my submit handler must be correct, otherwise main.php would never be called in the first place.

So my question is what am I doing wrong? I dont know if it makes a difference, but main.php is a standard php file whereas APIEmailConnection.php is a class (and I dont namespace it).

Any advice on what the problem could be appreciated.

Thanks

Try checking the relevence to the section from which you include or use the main.php file. Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM