Changing JQUERY Ajax GET to POST

Hi,

I am modifying someone's signup code right now on the main page. He is using Jquery Ajax on a modal to allow user to sign up to the website, but he was using GET.

I am trying to modify the code to use POST, but it isnt working. I am not even sure how / where i can see the error log, and whether the error is in the jquery, or php.

His code on script.js :

	
var scriptUrl="signUp.php?fName="+fname+"&lName="+lname+"&email="+email+"&institution="+institution+"&pass1="+pass1+"&pass2="+pass2;
                $.ajax({
			url: scriptUrl,
			type: 'get',
			dataType: 'html',
			async: false,
			success: function(data) {
				result = data;
				if(result==2){
					$('#error2').fadeIn(850);
					$('#newMail').css('box-shadow','0 0 10px 1px #f00');
...etcetc

Open in new window

                         
The signUp.php :

<?php
	include 'common.php';

	

	if(!emailExists($_GET['email'])){ 
		if($_GET['pass1']==$_GET['pass2']){
			$password=$_GET['pass1'];
			$uppercase = preg_match('@[A-Z]@', $password);
			$lowercase = preg_match('@[a-z]@', $password);
			$number    = preg_match('@[0-9]@', $password);

			if(!$uppercase || !$lowercase || !$number || strlen($password) < 8) {
			  echo (4);//password insecure
			}else {
				if(filter_var($_GET['email'], FILTER_VALIDATE_EMAIL)) {
					$newUser = new User($_GET['fName'],$_GET['lName'],$_GET['pass'],$_GET['email'],1,$_GET['institution']);
					createUser($newUser,0);
					echo(0);
				}
				else {
					echo(5);// invalid address
				}
			}
		}else{
			echo(3);//passwords dont match
        }
	}

    else{
		echo(2);//email exists
	}
	
?>

Open in new window

                         


Now, my code on scripts.js is

  $.ajax({
            url:signUp.php,
            type:'post',
         //   async: false,
            dataType: 'html',
            data : {
                'fName': fname,
                'lName': lname,
                'email':email,
                'institution':institution,
                'pass1':pass1,
                'pass2':pass2
            },
             success: function(data) {
				result = data;
				if(result==2){
					$('#error2').fadeIn(850);
					$('#newMail').css('box-shadow','0 0 10px 1px #f00');
.....etcetc

Open in new window


And on signUp.php i simply change all $_GET to $_POST.

- Am I doing this wrong?
- where is the error, and why is it not showing up? XAMPP php error log shows nothing.

Thank you
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NeverEndingFlashStoriesAuthor Commented:
Sorry,
...

I did not encase signUp.php inside apostrophies in the ajax call.

I would like to change the question to : Why did this error not show up in console, and how do I detect this error?
Marco GasiFreelancerCommented:
To get error from ajax calls I use this code:

             success: function(data) {
				result = data;
				if(result==2){
					$('#error2').fadeIn(850);
					$('#newMail').css('box-shadow','0 0 10px 1px #f00');
             },
	     error: function ( jqXHR, textStatus, errorThrown )
	    {
		console.log( jqXHR + " textStatus: " + textStatus + ", errorThrown: " + errorThrown );
	    }
} );

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NeverEndingFlashStoriesAuthor Commented:
Thanks Marco,

I threw your code there, but the message isn't showing up on console. Is it possible that jquery does not think of it as an error to not have enclosed the url page in apostrophies? Why would that do so?
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

Julian HansenCommented:
This code gave the attached error in the console
$(document).ready(function(){
	$.ajax({
		url: signup.php
	});
})

Open in new window

Screen shot
Julian HansenCommented:
Are you sure you have your console configured to show all errors - have you tried in another browser FF / Chrome (whichever you are not using)

Above results were from FF
Marco GasiFreelancerCommented:
It gives error to me too in Chrome.
Marco GasiFreelancerCommented:
NeverEndingFlashStoriesAuthor Commented:
Hi Julian and Marco,

I have tried both firefox and internet explorer, but no dice. I have combined using on document ready that Julian gave and the error function that marco gave, but nothing. I have to mention that the modal i am using is a reveal modal from foundations. Would that affect error messages at all?
NeverEndingFlashStoriesAuthor Commented:
Both solution(s) are correct and answered the question. The problem must lie elsewhere.
Julian HansenCommented:
No - do you have a link where we can see the error.
NeverEndingFlashStoriesAuthor Commented:
No :( I wish I did, i don't have this anywhere but on local XAMPP server.
Marco GasiFreelancerCommented:
You can still do it: if you can put the page online we can try to see the problem...
NeverEndingFlashStoriesAuthor Commented:
Thanks Marco, Julian,

That may take a little while, since this guy had an index.php page that calls a header.php page containing the login that uses foundations , which then calls a signuplayout.php to show the modal, which then calls the script.js, which then calls signup.php through ajax.

...it was so roundabout i had to write this down to understand the process, but basically it looks like i'll have to upload the whole project online. I'll have to do this anyway to be able to appropriately test a few responsive functionalities. When I do, I will open a question specific as to why my browser isn't showing jquery errors.

Thanks for your time and tips. Even if the error didn't show up, the error code and document ready functions should be standard practice in my coding.
Marco GasiFreelancerCommented:
I believed you were using document.ready yet since it's a starting point of each jQuery tutoorial and manual. If you're handing a pre-existent site and if you're new to jQuery, I would suggest this good manual which gave me a good starting point - and I didn't go deep from there :-D http://www.sitepoint.com/books/jquery2/
NeverEndingFlashStoriesAuthor Commented:
Thanks Marco,

I am indeed new - was doing actionscript 3 before this project falls on my lap. Started modifying some PHP and mysql last month, CSS3/SAS and HTML last week, and just yesterday hit the jquery/ajax thing. Having object oriented background makes understanding things a breeze, but error handling, syntax, and all the web development idiosyncrasies escapes me, and i think will be my growing pains.

I will check the book out :)
Marco GasiFreelancerCommented:
Then I suggest even a Php book from the SitePoint guys: http://www.sitepoint.com/books/phpmysql5/ It can help you to find your way in the strange and self-contradictory world of Php... Mmmh, I'll have to ask for commissions to SitePoint ;-)
NeverEndingFlashStoriesAuthor Commented:
Haha :) thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.