Required help in AJAX to PHP via post methord

Discussion in 'PHP' started by Seupoj, Jan 15, 2014.

  1. #1
    Hello i would require help with the given script
    AJAX
    
            $.ajax({
                type: "post",
                url: "http://localhost/raffle.php",
                dataType: "json",
                data: {
                    "postraffle": "true",
                    "title": $("#rtitle").val(),
                    "message": $("#mess").val(),
                    "maxentry": $("#maxentry").val(),
                    "duration": $("#durr").val(),
                    "filter": $("#reffil").val(),
                    "split": $("input[name=split]:checked").val(),
                    "pub": $("input[name=rafflepub]:checked").val(),
                    "stype": $("input[name=stype]:checked").val(),
                    "invo": $("input[name=invo]:checked").val(),
                    "items[]": itms,
                    "games[]": gmes,
                    },
                success: function(data){
                    if(data.status == "fail")
                    {
                        alert(data.message);
                        $("#rafBut").removeAttr("disabled");
                        $("#rafBut").attr("value", "Raffle it!");
                    }
    
                    else if(data.status == "ok")
                    {
                    window.location.href = "http://localhost/raffle.php";
                    }
    
                }
            });
     
    </script>
    Code (markup):
    And here is the php script
    <?php
    $data = array(
        'status' => 'fail',
        'message' => 'Failed to save data',
    );
    echo json_encode($data);
    PHP:
    You can see the script live here admin.tftrg.com/Prototype/raffle.html
    I want all of the above data to transmit from HTML using ajax to php
    Well currently it shows an error FAILED TO TRANSMIT DATA
    Some help would be really appricated
    Thanks!
     
    Seupoj, Jan 15, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Uhm - of course it transmits "Failed to save data" - it's the only thing in the PHP-file. I'm confused as to what the problem is - it seems to be working just fine, from what you've posted here?
     
    PoPSiCLe, Jan 15, 2014 IP
  3. Seupoj

    Seupoj Greenhorn

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    23
    #3
    Is there an way that i can echo all information of the ajax script to php thats just i wanted.
     
    Seupoj, Jan 15, 2014 IP
  4. Seupoj

    Seupoj Greenhorn

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    23
    #4
    Anyone?
     
    Seupoj, Jan 23, 2014 IP
  5. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #5
    You could do it like this:
    
    <?php
    echo json_encode($_POST);
    ?>
    
    Code (markup):
    You should really check what's being posted and outputted. But that's up to you.
     
    HuggyStudios, Jan 24, 2014 IP