PDA

View Full Version : ajax post with serialize isn't working.


Sim
01-13-2010, 04:56 AM
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
<?
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...";
}*/
?>

my html:

<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>

my JS:
$(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());
});

});

bdl
01-13-2010, 06:24 PM
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.

Sim
01-13-2010, 06:36 PM
if i run the php file by itself it works fine, it just doesn't call the php file at all.

A1ien51
01-14-2010, 03:18 PM
Use a tool such as Fiddler or Firebug and see what happens when the Ajax call is made [if it is made]

Eric