Jump to content

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.

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.