1 Replies - 347 Views - Last Post: 12 February 2013 - 11:25 AM

#1 matn89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 12-February 13

Passing data to externam PHP file from JavaScript File

Posted 12 February 2013 - 10:01 AM

Hi Everyone

I have the following js function which is located in its own file named checkUsername.js :



function checkUsername(){
var status = document.getElementById("usernamestatus");
var u = document.getElementById("uname").value;
if(u != ""){
status.innerHTML = 'checking...';
var hr = new XMLHttpRequest();
hr.open("POST", "passUsername.php", true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
status.innerHTML = hr.responseText;
}
}
var v = "name2check="+u;
hr.send(v);
}
}







I have the following PHP file named passUsername.php which is located in the same directory as checkUsername.js



<?php

include_once('../classes/validation.class.php');



echo 'Hello'; // Testing purposes





?>






It seems the data is not being sent to the PHP file from the javascript file. On the HTML page the output "Checking..." appears but then nothing else. I have tried this with all code in the same file and it works, but I really do not want to jam everything into one file.

Clearly I am calling the PHP file incorrectly in the js function, would anyone be able to tell me how I should call it?

Thanks for your time!

Is This A Good Question/Topic? 0
  • +

Replies To: Passing data to externam PHP file from JavaScript File

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2875
  • View blog
  • Posts: 9,538
  • Joined: 12-December 12

Re: Passing data to externam PHP file from JavaScript File

Posted 12 February 2013 - 11:25 AM

Use value, not innerHTML.. twice.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1