Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Sim
    Sim is offline
    New Coder
    Join Date
    Feb 2009
    Posts
    82
    Thanks
    1
    Thanked 1 Time in 1 Post

    ajax post with serialize isn't working.

    as you can see i commented all code in the php file and just put a simple echo "test"; in it to see if its working.

    it was working when I didn't use serialization and just posted the names, but once I added serialization it didn't work.
    Its like not calling the php file now or something. ne help would be nice.
    my php crimegroupadd.php
    [code=text]<?
    session_start();
    require "../../../config.php";
    require "../../../libs/Smarty.class.php";


    /*/vars
    $name = strip_tags(mysql_real_escape_string($_POST['textCrimeGroupName']));
    $placement = strip_tags(mysql_real_escape_string($_POST['selectPlace']));
    $crimegroup = strip_tags(mysql_real_escape_string($_POST['selectCrimeGroup']));
    $game_name = strip_tags(mysql_real_escape_string($_POST['hidden']));
    */
    echo 'test';
    /*if($_SESSION['rpg_' . $game_name . 'userrank'] != 1)
    {
    die("You dont belong here");
    }


    //check if name not in use
    $result = mysql_query("SELECT cgID FROM crimegroups WHERE cgNAME='$name' AND game='$game_name'") or die(mysql_error());
    if(mysql_num_rows($result) == 0 && !empty($name))
    {
    if($placement == "First")
    {
    mysql_query("UPDATE crimegroups SET cgORDER=cgORDER+1 WHERE game='$game_name'") or die(mysql_error());
    mysql_query("INSERT INTO crimegroups(cgNAME, cgORDER, game) VALUES ('$name', '1', '$game_name')") or die(mysql_error());
    echo "Crime Group successfully added...";
    }
    elseif($placement == "After")
    {
    mysql_query("UPDATE crimegroups SET cgORDER=cgORDER+1 WHERE cgORDER>$crimegroup AND game='$game_name'") or die(mysql_error());
    mysql_query("INSERT INTO crimegroups(cgNAME, cgORDER, game) VALUES ('$name', '($crimegroup + 1)', '$game_name')") or die(mysql_error());
    echo "Crime Group successfully added...";
    }
    elseif($placement == "Before")
    {
    mysql_query("UPDATE crimegroups SET cgORDER=cgORDER+1 WHERE cgORDER<$crimegroup AND game='$game_name'") or die(mysql_error());
    mysql_query("INSERT INTO crimegroups(cgNAME, cgORDER, game) VALUES ('$name', '($crimegroup - 1)', '$game_name')") or die(mysql_error());
    echo "Crime Group successfully added...";
    }
    }
    else
    {
    echo "Name can not be same as another crime group name or blank...";
    }*/
    ?>[/code]

    my html:

    [code=text]<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
    <script src="{$adminpath}/js/crimegroupadd.js" type="text/javascript"></script>

    <form name="form1" id="form1" method="post" action="">
    <table width="100%" border="1">
    <tr>
    <td><strong>Crime Group Name:</strong></td>
    <td><label>
    <input name="textCrimeGroupName" type="text" id="textCrimeGroupName">
    <input name="hidden" type="hidden" id="hidden" value="{$game}" />
    </label></td>
    </tr>
    <tr>
    <td><strong>Place:</strong> </td>
    <td><label>
    <select name="selectPlace" id="selectPlace" id="selectPlace">
    <option value="First" selected="selected">First</option>
    <option value="After">After</option>
    <option value="Before">Before</option>
    </select>
    {html_options name="selectCrimeGroup" options=$CrimeGroups selected=$CrimeGroupsSel}</label></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><label>
    <!-- JQuery -->
    <div id="test">
    <button id="save">Save</button>
    </div>
    <div id="error" style="color:red">
    </div>
    <!-- End of jquery -->
    </label></td>
    </tr>
    </table>
    </form>[/code]

    my JS:
    [code=text]$(document).ready(function(){
    $("#save").mouseup(function () {
    $("#error").html("Saving...");
    var CrimeGroupName = document.form1.textCrimeGroupName.value;
    var CrimeGroupWhere = document.form1.selectPlace.value;
    var CrimeGroup = document.form1.selectCrimeGroup.value;
    var GameName = document.form1.hidden.value;

    $.post("./gamefiles/admin/js/ajax/crimegroupadd.php", $('#form1').serialize()),
    function(data) {
    $("#error").html(data);
    };
    alert($('#form1').serialize());
    });

    }); [/code]

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Please edit your post and use the proper CODE tags. Proper indentation doesn't hurt.

    Point out the code you're referring to. Let's strip this down to the essentials - the data that is being sent and the receiving JS code. We don't need to see all your SQL statements and other function calls.

    Put another way - run your PHP script by itself. Look at the output and plug that output into your JS code. It's just data - we don't need to see what gets us to that data, just how the JS interacts with it, correct? So it becomes a PHP troubleshooting issue first (wrong forum), and then after you nail down the exact data being returned, you can see how jQuery or straight JS code handles it.

  • #3
    Sim
    Sim is offline
    New Coder
    Join Date
    Feb 2009
    Posts
    82
    Thanks
    1
    Thanked 1 Time in 1 Post
    if i run the php file by itself it works fine, it just doesn't call the php file at all.

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Use a tool such as Fiddler or Firebug and see what happens when the Ajax call is made [if it is made]

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

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