What here is wrong?

Status
Not open for further replies.

Unidentified

Living the Developer Life...
Jun 19, 2012
144
20
I am new to using ajax and somink is wrong because it aint posting.

Test.php


Code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js">
</script>
<script type="text/javascript" >
$(function() {
$("#ntb").click(function() {
var nt = $("#nt").val();
var data=$('#nt').serialize();
if(nt=='')
{
$('.success').fadeOut(200).hide();
$('.error').fadeOut(200).show();
}
else
{
$.ajax({
type: "POST",
url: "../ajax/post.php?ref=profile&goto=home&ex=newpost",
data: dataString,
success: function(){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
}
});
}
return false;
});
});
 
</script>
 
 
<form method="post" name="form">
<input id="nt" name="nt" type="text" />
<input type="submit" style="display:block;" name='ntb' id='ntb'  class="Buttonchat" value="Post" />
</form>
<div>
<span class="error" style="display:none"> Please Enter Valid Data</span>
<span class="success" style="display:none"> Registration Successfully</span>
</div></form&gt;

../ajax/post.php?ref?ref=profile&goto=home&ex=newpost
PHP:
<?php
 
 
 
include '../core/init.php';
 
 
 
if(isset($_GET['ex'])){
 
if($_GET['ex'] == 'newpost' && isset($_POST['nt']) && isset($_POST['ntb'])){
 
mysql_query("INSERT INTO `post` (`myid`, `text`) VALUES ('".$_SESSION['id']."', '".mysql_real_escape_string($_POST['nt'])."')");
 
}
 
}
 
?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
You're making the AJAX request a 'POST' type, so change all $_GET to $_POST in your PHP script, see if that helps.
 

Unidentified

Living the Developer Life...
Jun 19, 2012
144
20
I got rid of the $_GET's before you commented lol that was to set the url before coz it use to say ?ref=profile&goto=home&ex=newpost
I will post the new stuff :)
 

Unidentified

Living the Developer Life...
Jun 19, 2012
144
20
Test.php
Code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js">
</script>
<script type="text/javascript" >
$(function() {
$("#ntb").click(function() {
var nt = $("#nt").val();
var data=$('#nt').serialize();
if(nt=='')
{
$('.success').fadeOut(200).hide();
$('.error').fadeOut(200).show();
}
else
{
$.ajax({
type: "POST",
url: "../ajax/post.php",
data: dataString,
success: function(){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
}
});
}
return false;
});
});
 
</script>
 
 
<form method="post" name="form">
<input id="nt" name="nt" type="text" />
<input type="submit" style="display:block;" name='ntb' id='ntb'  class="Buttonchat" value="Post" />
</form>
<div>
<span class="error" style="display:none"> Please Enter Valid Data</span>
<span class="success" style="display:none"> Registration Successfully</span>
</div></form&gt;

../ajax/post.php
PHP:
<?php
 
include '../core/init.php';
 
if(isset($_POST['nt']) && isset($_POST['ntb'])){
mysql_query("INSERT INTO `post` (`myid`, `text`) VALUES ('".$_SESSION['id']."', '".mysql_real_escape_string($_POST['nt'])."')");
}
?>
 
Status
Not open for further replies.

Users who are viewing this thread

Top