Ajax & require

Discussion in 'Javascript' started by Jason Carlton, Nov 24, 2009.

  1. I'm having a hard time tracking down an error, so I'm hoping you guys
    can help me save a few hours of work.

    If I require a file in the parent page, do I need to require it again
    in a child page called via Ajax in order to use it there?

    Logic says that I do, but I'm getting an error that says:

    Fatal error: Cannot redeclare xml2array() (previously declared in /
    home/mydomain/public_html/includes/inc.xml2array.php:3)


    TIA,

    Jason
     
    Jason Carlton, Nov 24, 2009
    #1
    1. Advertising

  2. On Nov 23, 7:10 pm, Jason Carlton <> wrote:
    > I'm having a hard time tracking down an error, so I'm hoping you guys
    > can help me save a few hours of work.
    >
    > If I require a file in the parent page, do I need to require it again
    > in a child page called via Ajax in order to use it there?
    >
    > Logic says that I do, but I'm getting an error that says:
    >
    > Fatal error: Cannot redeclare xml2array() (previously declared in /
    > home/mydomain/public_html/includes/inc.xml2array.php:3)
    >
    > TIA,
    >
    > Jason



    I'm still not sure of the answer, but for any future reader with a
    similar error, using require_once() instead of require() solved the
    problem.

    - J
     
    Jason Carlton, Nov 24, 2009
    #2
    1. Advertising

  3. Jason Carlton

    Erwin Moller Guest

    Jason Carlton schreef:
    > On Nov 23, 7:10 pm, Jason Carlton <> wrote:
    >> I'm having a hard time tracking down an error, so I'm hoping you guys
    >> can help me save a few hours of work.
    >>
    >> If I require a file in the parent page, do I need to require it again
    >> in a child page called via Ajax in order to use it there?
    >>
    >> Logic says that I do, but I'm getting an error that says:
    >>
    >> Fatal error: Cannot redeclare xml2array() (previously declared in /
    >> home/mydomain/public_html/includes/inc.xml2array.php:3)
    >>
    >> TIA,
    >>
    >> Jason

    >
    >
    > I'm still not sure of the answer, but for any future reader with a
    > similar error, using require_once() instead of require() solved the
    > problem.
    >
    > - J


    Hi,

    You are asking a PHP question in a javascript group.
    Don't. ;-)

    For your information:
    In PHP:
    require(file): Includes the file and generates an error if it fails. (As
    opposed to include()).
    require_once(file): Includes the file ONLY if it hasn't been included
    before. If it has been included before, this statement is ignored.

    Apparantly you try to include the same file two times, and thus
    redeclared xml2array, what generated the error.

    It is better to fix your code in a serious way (= remove the second
    require()), and not use require_once() to fix the problem.

    For more information try comp.lang.php

    Regards,
    Erwin Moller


    --
    "There are two ways of constructing a software design: One way is to
    make it so simple that there are obviously no deficiencies, and the
    other way is to make it so complicated that there are no obvious
    deficiencies. The first method is far more difficult."
    -- C.A.R. Hoare
     
    Erwin Moller, Nov 24, 2009
    #3
  4. On Nov 24, 5:55 am, Erwin Moller
    <> wrote:
    > Jason Carlton schreef:
    >
    >
    >
    > > On Nov 23, 7:10 pm, Jason Carlton <> wrote:
    > >> I'm having a hard time tracking down an error, so I'm hoping you guys
    > >> can help me save a few hours of work.

    >
    > >> If I require a file in the parent page, do I need to require it again
    > >> in a child page called via Ajax in order to use it there?

    >
    > >> Logic says that I do, but I'm getting an error that says:

    >
    > >> Fatal error: Cannot redeclare xml2array() (previously declared in /
    > >> home/mydomain/public_html/includes/inc.xml2array.php:3)

    >
    > >> TIA,

    >
    > >> Jason

    >
    > > I'm still not sure of the answer, but for any future reader with a
    > > similar error, using require_once() instead of require() solved the
    > > problem.

    >
    > > - J

    >
    > Hi,
    >
    > You are asking a PHP question in a javascript group.
    > Don't. ;-)



    Ajax always makes it difficult to know where to ask these questions.
    Had I asked this question in comp.lang.php, they would have said that
    it's an Ajax question so it would belong in comp.lang.javascript.

    We need an Ajax-specific NG.
     
    Jason Carlton, Nov 26, 2009
    #4
  5. Jason Carlton wrote:

    > On Nov 24, 5:55 am, Erwin Moller wrote:
    >> Jason Carlton schreef:
    >> > On Nov 23, 7:10 pm, Jason Carlton <> wrote:
    >> >> Fatal error: Cannot redeclare xml2array() (previously declared in /
    >> >> home/mydomain/public_html/includes/inc.xml2array.php:3)

    >> [...]
    >>
    >> > I'm still not sure of the answer, but for any future reader with a
    >> > similar error, using require_once() instead of require() solved the
    >> > problem.

    >>
    >> [...]
    >> You are asking a PHP question in a javascript group.
    >> Don't. ;-)

    >
    > Ajax always makes it difficult to know where to ask these questions.
    > Had I asked this question in comp.lang.php, they would have said that
    > it's an Ajax question so it would belong in comp.lang.javascript.


    Had you gotten yourself informed before posting what "Ajax" really is (and
    read the error message carefully to begin with), you could have broken it
    down for them to the PHP issue that it is. Besides, I do not think people
    in comp.lang.php are so stupid not to see that it is a PHP problem, and you
    should not assume that they are.

    > We need an Ajax-specific NG.


    We don't.


    PointedEars
    --
    Use any version of Microsoft Frontpage to create your site.
    (This won't prevent people from viewing your source, but no one
    will want to steal it.)
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)
     
    Thomas 'PointedEars' Lahn, Nov 27, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    20
    Views:
    1,942
    d1srupt3r
    Mar 31, 2008
  2. darrel

    beginner AJAX questions (AJAX.net)

    darrel, Apr 27, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    2,478
    Flinky Wisty Pomm
    Apr 28, 2006
  3. jobs
    Replies:
    0
    Views:
    386
  4. minnie
    Replies:
    1
    Views:
    762
    Andrew Thompson
    Dec 13, 2006
  5. Paul
    Replies:
    4
    Views:
    322
    Cowboy \(Gregory A. Beamer\)
    Mar 28, 2008
Loading...

Share This Page