The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AJAX post bug
#1
I have a situation where I post form to php parser via ajax call:

Example
$.post('parser.php', {
post_var1:var1,
post_var2:var
},

function(data)
{
console.log("Response: "+data);
});


then in the parser.php I submit this data to db. So I need to include init.php, header.php and securePage in the parser.

Example
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/users/init.php';
require_once $abs_us_root.$us_url_root.'users/includes/header.php';
if (!securePage($_SERVER['PHP_SELF'])){die();}

if($f_var1 = $_POST['post_var1'] ) $fields[var1] = $f_var1;
if($f_var2 = $_POST['post_var2'] ) $fields[var2] = $f_var2;

$success = $db->insert('devices',$fields);

if(success) echo "1";
else echo "0";
?>


This should be pretty straight forward right?

Well the problem is that when I get echo from parser.php, the console.log prints the whole header (users/includes/header.php) + my echo 0 or 1.

I tryed to flush() and ob_flush() and then echo with no success. Problem occurs when I include header.php. If header.php is not included, the echo works OK. But then I'm stuck without DB class...

I also searched header.php and not found any of the echo routines. Also header.php is still original userSpice.

Also may I say that the header is echoed back regardless of what the parser.php is doing. Even if I comment out db->insert and $fields I'm stuck with that.

But there is one more interesting thing. If I access parser.php directly, the echo does show correct. Only 0 is echoed back (or 1 if the db->insert is successful).

Regards,
Jakob
  Reply


Messages In This Thread
AJAX post bug - by JUG - 04-12-2017, 03:38 AM
AJAX post bug - by karsen - 04-13-2017, 08:27 PM
AJAX post bug - by JUG - 04-18-2017, 03:25 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)