SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict trican's Avatar
    Join Date
    Sep 2003
    Location
    someplace
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery .post / php problem

    Hi all,

    I'm having a problem using jQuery $.post with a php file. I have the following code:

    [code=javascript]
    $.post( "http://www.mywebsite.com/myfile.php", {v1: v1_value, v2 : "string", v3: v3_value});
    [/code]

    I've checked in firebug that the "data values" are as expected going into the .post function. So I thought the problem might lie with the php code, which is as follows:

    [code=php]
    <?php
    // Sanity check
    $cmd = "touch ajax_call.txt";
    exec("$cmd 2>&1", $array);

    $v1 = $_POST['img'];
    $v2 = $_POST['prog'];
    $v3 = $_POST['value'];

    // other code
    ?>
    [/php]

    The sanity check of file touching is happening. When I check the apache error_logs file, it says PHP Notice: Undefined index: v1 and there are similar errors for v2 and v3.

    I don't understand what I'm doing wrong? or is anything else I can try to debug this further?

    Many thanks!
    Free Image Editing Webapp, includes
    easy to use creative transformations to
    enrich your digital photographs @www.PureRGB.com

  2. #2
    SitePoint Evangelist speda1's Avatar
    Join Date
    Jan 2002
    Posts
    550
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your parameter names do not match.

    $v1 = $_POST['v1'];
    $v2 = $_POST['v2'];
    $v3 = $_POST['v3'];

  3. #3
    SitePoint Addict trican's Avatar
    Join Date
    Sep 2003
    Location
    someplace
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi speda1

    Thanks for the reply, that was a mistake when i posting my original question, the code is in fact:

    $v1 = $_POST['v1'];
    $v2 = $_POST['v2'];
    $v3 = $_POST['v3'];


    So thats not the explanation. any other thoughts? Any way I could debug this?
    Free Image Editing Webapp, includes
    easy to use creative transformations to
    enrich your digital photographs @www.PureRGB.com

  4. #4
    SitePoint Addict trican's Avatar
    Join Date
    Sep 2003
    Location
    someplace
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just to add I've tried $_GET in the php file as well, which manually works with the url I'd expect, i.e.

    test.php?v1=1&v2=2&v3=3

    So should the php file be using $_POST or $_GET
    Free Image Editing Webapp, includes
    easy to use creative transformations to
    enrich your digital photographs @www.PureRGB.com

  5. #5
    SitePoint Addict trican's Avatar
    Join Date
    Sep 2003
    Location
    someplace
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Caught the problem - thanks for looking! seems like it was a typo
    Free Image Editing Webapp, includes
    easy to use creative transformations to
    enrich your digital photographs @www.PureRGB.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •