The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Ajax request in cPanel plugin : Does it works ?

Discussion in 'cPanel Developers' started by tizoo, Nov 28, 2011.

  1. tizoo

    tizoo Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    Hi all,

    I'm currently trying to develop a plugin for cPanel and want to use jQuery in it.

    When I try to load data from an ajax query, I didn't succeed on getting the data from the php script I call.

    Firebug show me that the php script is well accessed, but the data returned are always the same :

    Code:
    <!-- cPanel [11.30] (pro,dev) Copyright (c) 2011 cPanel, Inc. Licensed on xxx -->
    Does it means for security reasons it is not possible to make ajax requests or is there a documentation that I didn't find and which explains how to do such requests ?

    Thanks in advance,
    Philippe
     
  2. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Just a couple of quick questions, the PHP script you are calling that returns the data:

    - Is it being served over any of the cPanel ports (2086,2087,2083,2082,2095,2096)?
    - Are you calling it via an absolute URL or a relative URL?
     
  3. tizoo

    tizoo Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    Hi cPanelDavidG,

    Thanks for your answer. I think you pointed the problem I have.

    I call the PHP script with a relative URL. I don't know how to call it with an absolute URL due to the cpanel session part. I don't use the cPanel special ports (2086, 2087, ...) because they are often closed in firewalls.

    But I didn't have a look to see if the session information is available through the CPANEL class (I use LivePHP).

    Do I have to call the script with an absolute URL ? In this case, is there a rule to construct such URL ?

    Thanks in advance for any tips,
    Philippe
     
  4. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    if you use relative URLs, you shouldn't need the port.
    1) include the cpsession token in URL (that is, if they are enabled on the system) if you're constructing URL paths
    2) have you try logging in and manually going to that php script that the JS is polling? Your browser should receive the same info that an AJAX call would.
    3) you don't need to be concerned with the session. Your browser (via the JQuery HTTP functions) should be passing any HTTP session cookie information that would be needed.

    Do you have some example code?

    Regards,
    -DavidN
     
  5. tizoo

    tizoo Well-Known Member

    Joined:
    Jan 6, 2004
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    Hi DavidN,

    According to your answer, I was convinced that the problem was between the chair and the keyboard...

    I thus had a better look to my code and found that the problem was due to the called PHP script that didn't generate the correct data to be retrieved by a call to it (normal or ajax call).

    Thanks very much for your help to find the real problem.

    Regards,
    Philippe
     
Loading...

Share This Page