Dealing with POST data

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Dealing with POST data

Post by spacebiscuit »

Hi,

I'm using a simple bit of javascript to popup a prompt for user input which is posted back to a php script.

The HTML form is as follows:

Code: Select all

<form action="test.php" method="post" name="contactForm" id="contactForm">
  <p><input name="customerid" id="customerid" type="text" size="30" value="Input Your Customer ID" /></p>
  <p><input type="submit" id="submit" name="submit" value="Send" /></p>
</form>
As you can see the data is posted back to test.php

In my javascript I have the following which I thought determined the data sent back and to where it is sent?

Code: Select all

$.ajax({
	type: "POST",
	url: "test.php",
	data: "customerid=" + customerid,
	error: function() {
		$('.error').hide();
		$('#sendError').slideDown('slow');
	   },
	success: function () {
	       $('.error').hide();
	       $('.success').slideDown('slow');
               $('form#contactForm').fadeOut('slow');
	}				
});
However if I change the 'url', 'type' and 'data' the data is still sent to the page. It seems that the only factor determining this is the html form?

Thanks.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: Dealing with POST data

Post by spacebiscuit »

It seems using $_SERVER['PHP_SELF'] by passes anything the the jquery attempts to setup.

Is this bad practice?
Gopesh
Forum Contributor
Posts: 143
Joined: Fri Dec 24, 2010 12:48 am
Location: India

Re: Dealing with POST data

Post by Gopesh »

Hi,Try without using the action="test.php" in the form tag.
Post Reply