Jump to content

jquery php result


SetToLoki

Recommended Posts

I made a form that submits data to a php form

 

my code to subit the form looks like this

<script type="text/javascript"> 
$(function() { 
// alert("running"); 
  $(".button").click(function() { 
  
  var FirstName = $("input#FirstName").val(); 
  var Surname    = $("input#Surname").val(); 
  var Ext       = $("input#Ext").val(); 
  var Mobile   = $("input#Mobile").val(); 
  var Room       = $("input#Room").val(); 
  var Office    = $("select#Office").val(); 
  var userid   = $("input#userid").val(); 
  var dataString = 'userid='+ userid + ' FirstName='+ FirstName + '&Surname=' + Surname + '&Ext=' + Ext + '&Mobile=' + Mobile + '&Room=' + Room + '&Office=' + Office; 
  //alert (dataString);return false; 
  $.ajax({ 
    type: "POST", 
    url: "forms/php/user_info.php", 
    data: dataString, 
    success: function() { 
         //Runs on Form Sucsess 
     $('#User_info_form').html("<div id='message'></div>"); 
      $('#message').html("<h2>Changes Made!</h2>").hide().fadeIn(1500, function() {$('message');}); 
     $('#form').load('forms/user_info.php'); 
      //END 
    } 
  }); 
  return false; //Stops form from refreshing page 
   }); //end button click 
  });//End doc.ready 
</script>

 

it submits the form without reloading the page and works good at that.

my problem is I am not sure how to view the php page to see if it is doing what it should be doing. is there away to make the $.ajax function return the php page output, it sounds like it should be really simple but I am struggling to understand the web sites I have been reading about it all

 

 

EDIT:

 

<?
if ((isset($_POST['FirstName'])) && (strlen(trim($_POST['FirstName'])) > 0)) {
$FirstName = stripslashes(strip_tags($_POST['FirstName'])); }
if ((isset($_POST['Ext'])) && (strlen(trim($_POST['Ext'])) > 0)) {
$Ext = stripslashes(strip_tags($_POST['Ext'])); }
if ((isset($_POST['Mobile'])) && (strlen(trim($_POST['Mobile'])) > 0)) {
$Mobile = stripslashes(strip_tags($_POST['Mobile'])); }
if ((isset($_POST['Office'])) && (strlen(trim($_POST['Office'])) > 0)) {
$Office = stripslashes(strip_tags($_POST['Office'])); }
if ((isset($_POST['Room'])) && (strlen(trim($_POST['Room'])) > 0)) {
$Room = stripslashes(strip_tags($_POST['Room'])); }
if ((isset($_POST['SurName'])) && (strlen(trim($_POST['SurName'])) > 0)) {
$FirstName = stripslashes(strip_tags($_POST['SurName'])); }
if(isset($_POST['id']))
{
	$id = $_POST['id']
	require_once'../../inc/dbconnect.php';
	$id = $_POST['userid'];
	global $db_host, $db_user, $db_pass, $db_name;
	$db = new MySQL($db_host, $db_user, $db_pass, $db_name);

	$sql = "INSERT INTO userinfo (id, FirstName, Ext, Mobile, Office, Room, SurName) VALUES ('$id','$FirstName','$Ext','$Mobile','$Office','$Room','$SurName') ON DUPLICATE KEY UPDATE FirstName=VALUES(FirstName), Ext=VALUES(Ext), Mobile=VALUES(Mobile), Office=VALUES(Office), Room=VALUES(Room), SurName=VALUES(SurName)";

	$db->query($sql);

	echo $db->error();
}
?>

 

the php file I am sending it to - it doesn't seem to work but I can't view it after the ajax request to see if it returns an error

Link to comment
Share on other sites

I made a form that submits data to a php form

 

my code to subit the form looks like this

<script type="text/javascript"> 
$(function() { 
// alert("running"); 
  $(".button").click(function() { 
  
  var FirstName = $("input#FirstName").val(); 
  var Surname    = $("input#Surname").val(); 
  var Ext       = $("input#Ext").val(); 
  var Mobile   = $("input#Mobile").val(); 
  var Room       = $("input#Room").val(); 
  var Office    = $("select#Office").val(); 
  var userid   = $("input#userid").val(); 
  var dataString = 'userid='+ userid + ' FirstName='+ FirstName + '&Surname=' + Surname + '&Ext=' + Ext + '&Mobile=' + Mobile + '&Room=' + Room + '&Office=' + Office; 
  //alert (dataString);return false; 
  $.ajax({ 
    type: "POST", 
    url: "forms/php/user_info.php", 
    data: dataString, 
    success: function() { 
         //Runs on Form Sucsess 
     $('#User_info_form').html("<div id='message'></div>"); 
      $('#message').html("<h2>Changes Made!</h2>").hide().fadeIn(1500, function() {$('message');}); 
     $('#form').load('forms/user_info.php'); 
      //END 
    } 
  }); 
  return false; //Stops form from refreshing page 
   }); //end button click 
  });//End doc.ready 
</script>

 

it submits the form without reloading the page and works good at that.

my problem is I am not sure how to view the php page to see if it is doing what it should be doing. is there away to make the $.ajax function return the php page output, it sounds like it should be really simple but I am struggling to understand the web sites I have been reading about it all

 

 

EDIT:

 

<?
if ((isset($_POST['FirstName'])) && (strlen(trim($_POST['FirstName'])) > 0)) {
$FirstName = stripslashes(strip_tags($_POST['FirstName'])); }
if ((isset($_POST['Ext'])) && (strlen(trim($_POST['Ext'])) > 0)) {
$Ext = stripslashes(strip_tags($_POST['Ext'])); }
if ((isset($_POST['Mobile'])) && (strlen(trim($_POST['Mobile'])) > 0)) {
$Mobile = stripslashes(strip_tags($_POST['Mobile'])); }
if ((isset($_POST['Office'])) && (strlen(trim($_POST['Office'])) > 0)) {
$Office = stripslashes(strip_tags($_POST['Office'])); }
if ((isset($_POST['Room'])) && (strlen(trim($_POST['Room'])) > 0)) {
$Room = stripslashes(strip_tags($_POST['Room'])); }
if ((isset($_POST['SurName'])) && (strlen(trim($_POST['SurName'])) > 0)) {
$FirstName = stripslashes(strip_tags($_POST['SurName'])); }
if(isset($_POST['id']))
{
	$id = $_POST['id']
	require_once'../../inc/dbconnect.php';
	$id = $_POST['userid'];
	global $db_host, $db_user, $db_pass, $db_name;
	$db = new MySQL($db_host, $db_user, $db_pass, $db_name);

	$sql = "INSERT INTO userinfo (id, FirstName, Ext, Mobile, Office, Room, SurName) VALUES ('$id','$FirstName','$Ext','$Mobile','$Office','$Room','$SurName') ON DUPLICATE KEY UPDATE FirstName=VALUES(FirstName), Ext=VALUES(Ext), Mobile=VALUES(Mobile), Office=VALUES(Office), Room=VALUES(Room), SurName=VALUES(SurName)";

	$db->query($sql);

	echo $db->error();
}
?>

 

the php file I am sending it to - it doesn't seem to work but I can't view it after the ajax request to see if it returns an error

 

You could get the firebug extension for firefox and see the response you get from the page under the net tab

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.