Jump to content

New to Ajax, Simple Question


BK201

Recommended Posts

I'm just learning AJAX/JS and I'm trying to just make a basic, request. As I've found out you get no error messages when writing in JS so that's not helping. Nothing happens when I load the page. Any help is greatly appreciated, I've looked over several resources but I can't seem to figure out whats wrong.

 

test1.html

		<script language="javascript" type="text/javascript">
		<!--
		function createRequestObject() {
			var http;

			http = (window.XMLHttpRequest) ? new XMLHttpRequest() :
			new ActiveXObject("Microsoft.XMLHTTP");

			return http;
		}

		function processResponse() {
			var response;
			if (http.readyState == 4) {
				response = http.responseText;
				return response;
			}
		}

		function request(a, b) {
			http.open("GET", "test1.php?figure1=" + a + "&figure2=" + b, true);
			http.onreadystatechange = processResponse();
			http.send(null);
		}

		-->
		</script>

		createRequestObject(); request(1, 2); document.alert(response);

 

 

test1.php

<?php
    echo $_GET['figure1'] + $_GET['figure2'];
  ?>

Link to comment
https://forums.phpfreaks.com/topic/264456-new-to-ajax-simple-question/
Share on other sites

Try learning Jquery to handle your ajax it often replaces 40 lines of code with 4.

http://www.jquery.com

$.post("filename", {value to get : js value}, function(data){
   if (data.length>0){ 
     $("#div name for holding result").html(data);

Maybe this solution will assist you.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.