Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
C

charlieko

@charlieko
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • JSON response from PHP for ajax
    C charlieko

    I'm trying to create a php file that always returns a json as response. The problem is, it looks like it's returning a valid JSON, but jquery.ajax always says "invalid json." I copied and pasted the response and stuck it in jsonlint.com and it says it's valid json. Can anyone point out what I'm doing wrong here? Why can't jquery (and other json parser) parse this even it's a valid json?

    header('Content-type: application/json');

    include("database.php");
    require_once "../lib/JSON.php";

    $json = new Services_JSON();

    $method = strtolower($_SERVER['REQUEST_METHOD']);

    $value = array();

    // Open the database connection first, which will be used later.

    $DB = new DBConnect();

    $DB->NewConnection("localhost", "db_name", "db_role", "db_pw" );

    // assume method is get here
    if ($method == "get"){
    $value = getEmployees();
    }

    else if ($method == "post"){
    }

    else if ($method == "put"){
    }

    else {
    echo "Error - unknown http request method";
    }

    // tried without callback stuff but didn't work either
    echo $_GET['callback'] . '(' . $json->encode($value) . ');';

    Linux, Apache, MySQL, PHP help database javascript php com
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups