Jump to content

STUPID ISSUE


glenelkins

Recommended Posts

Hi

 

I have no idea whats going on with this , but im not getting any response text back from my AJAX query. Iv setup the files with test data. In the response function iv set it to check for the word HELLO which is echoed from the actual PHP file, but nothing is coming back. Funny thing is this code works fine on another site iv worked on:

 

AJAX functions

// Http Object
var http_request = false;
   
function makePOSTRequest(url, parameters) {

	http_request = false;

	if ( window.XMLHttpRequest ) { // Mozilla, Safari,...
        	
		http_request = new XMLHttpRequest();

        if ( http_request.overrideMimeType ) {

         	// set type accordingly to anticipated content type
    	        //http_request.overrideMimeType('text/xml');
        	    http_request.overrideMimeType('text/html');

        }

	} else if ( window.ActiveXObject ) { // IE

		try {
            	http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            	try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
            	} catch (e) {}
         	}
      	}

	if ( !http_request ) {

        	alert('Cannot create XMLHTTP instance');

		return false;
	}
      
        http_request.onreadystatechange = dovalidateregfields;

	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);

   }


function validate_reg_fields () {

	// Gather info
	var form = document.getElementById ( "regform" );

	var first_name = form.first_name.value;
	var last_name = form.last_name.value;
	var email = form.email.value;
	var username = form.username.value;
	var password = form.password.value;
	var retypepassword = form.retypepassword.value;

	// Create ajax post string
	var poststr = "first_name=" + first_name + "&last_name=" + last_name + "&email=" + email + "&username=" + username + "&password=" + password + "&retypepassword=" + retypepassword;

	makePOSTRequest ( 'scripts/reg_form_validation.php', poststr );


}

function dovalidateregfields() {

	if ( http_request.readyState == 4 ) {

		if ( http_request.responseText == "HELLO" ) {

			alert ( "HELLO" );

		}

	}

}

 

scripts/reg_form_validation.php

 

echo "HELLO";

Link to comment
Share on other sites

I have changed the code ( below ) to be simpler. But im still not getitng response text from FF, IE is fine, its wierd iv never had this problem before

 

<script language="javascript">

var http_object = false;

function validate_reg_fields() {

	alert ( "Validating" );

	var browser = navigator.appName;
   
   		if( browser == "Microsoft Internet Explorer" ){

        http_object = new ActiveXObject("Microsoft.XMLHTTP");

    } else {

        	http_object = new XMLHttpRequest();

	}

	if ( http_object ) {

		alert ( "Object OK" );

		http_object.onreadystatechange = function() {

			if ( http_object.readyState == 4 || http_object.readyState == "complete" ) {

				alert ( "Ready And Done" );

				alert ( http_object.responseText );
			}				
		}

		http_object.open ( "GET", "scripts/reg_form_validation.php" );
		http_object.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 			
		http_object.send(null);			

	} else {

		alert ( "Object Not Ok" );

	}

}
</script>

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.