DotDragnet
May 24, 2012, 08:22:34 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: jQuery posting and 404 error?  (Read 333 times)
sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« on: November 17, 2011, 04:10:57 PM »

I've got a form, a very long form, and in case people don't get to the end of completing it I'm trying to capture the initial personal data to store and allow someone to follow up from (if the person didn't complete the form). So, I've got some jQuery in place to do this.

Code:
jQuery(document).ready(function($){
$('#htel, #email, #dcsfnum').change(function(){
$.post("/includes/saveappform.inc.php", {id: $('#recid').val(), p: $('#afpost').val(), t: $('#aftitle').val(),
f: $('#fname').val(), s: $('#sname').val(), m: $('#afstatus').val(), d: $('#dob').val(),
a1: $('#addr1').val(), a2: $('#addr2').val(), tc: $('#city').val(), c: $('#county').val(),
pc: $('#postco').val(), ht: $('#htel').val(), wt: $('#wtel').val(), mt: $('#mtel').val(),
e: $('#email').val(), nn: $('#ninum').val(), dn: $('#dcsfnum').val()}, function(data) {
if (data) {
$('#recid').val(data);
}
});

});
});

So the idea is when a phone number, email address of their DCSF Number is entered, it triggers the JS to save/update the initial data in a db. The PHP is simple

Code:
<?php
require $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";

$recid updateAppFormDB((int)$_POST['id'], $_POST['p'], $_POST['t'], $_POST['f'], $_POST['s'], $_POST['m'],
$_POST['d'], $_POST['a1'], $_POST['a2'], $_POST['tc'], $_POST['c'], $_POST['pc'], $_POST['e'],
$_POST['ht'], $_POST['wt'], $_POST['mt'], $_POST['nn'], $_POST['dn']);

echo 
$recid;
?>

The updateAppFromDB() function just checks for an ID and updates the db table or inserts as new. Still got some additional security to put in place but you get the idea.

Anyway, I've got the files in the right place, yet I'm getting Firebug reporting a 404 error when my jQuery tries to post to the php file. Yet, it's still running the file, creating the record and returning the record ID. However it's not putting this record ID into the form (so it's continually creating a new record, not updating the existing one.

I don't get it. I've tried post, get (data is too long in reality though), I've moved the file about, and it just doesn't want to return a 200 status.

Am a bit lost Sad

PS. The page is protected on a site but am happy to give the password via PM if someone wants to look for themselves smile
« Last Edit: November 17, 2011, 04:17:12 PM by sarahA » Logged

samhs
Administrator
Hero Member
*****
Posts: 1713



View Profile WWW Awards
« Reply #1 on: November 17, 2011, 04:29:30 PM »

Have your tried a fully qualified domain? Or, the fact that it's protected - could that be the cause?
Logged

Loose adj a not held together; not fastened or firmly fixed in place
Lose verb to misplace something. To fail to keep or obtain something, especially because of a mistake, carelessness, etc.
---
Blog: www.ohwrite.co.uk
Twitter: www.twitter.com/samhs
sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« Reply #2 on: November 17, 2011, 04:34:58 PM »

I've tried a full domain yes. The page being protected is just WP protected/private page. You can view the page you just need a password to get to the form. I'll try it without.

I think it's WP messing it up somehow, as the data response is the front page HTML code. Possibly down to the protection as I've got other ajaxy stuff elsewhere and that all runs fine. Will do some tests. Cheers Sam smile
Logged

sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« Reply #3 on: November 17, 2011, 04:36:45 PM »

Update, removed the protection. Still coming up with 404 error Sad  Need to test it away from WP if my jQuery code is fine, then it's WP messing things up.
Logged

JasonD
Global Moderator
Hero Member
*****
Posts: 551



View Profile Awards
« Reply #4 on: November 17, 2011, 10:13:15 PM »

Code:
header('HTTP/1.1 200 OK');
Before the echo.

If it is working partly it cannot be a real 404. I'd blame Wordpress' rewrite trickery.
Logged
sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« Reply #5 on: November 17, 2011, 10:26:54 PM »

Cheers Jason, I'll give that a go in the morning. Yeah I think it's the permalink stuff too, although that's why I pulled the file out of the WP structure but obviously it's still possibly getting in the way.
Logged

sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« Reply #6 on: November 18, 2011, 09:51:56 AM »

That worked perfectly! Thanks again Jason, and thanks Sam for checking my code big grin
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!