Pass javascript variable to php -


i know had been disputed lot , short answer can't pass javascript variable php variable in same file. instead here want try: user inputs code, send php file post. there check if code matches code database , post again boolean there. in first file, tell user whether code correct or not. can achieved way? webdev newbie , trying learn.

jquery:

$.get( url, { userinput: value }, function( response ) {     if( response.status ) alert( "matches found" );     else alert( "no matches" ); } 

javascript:

function get( url ) {   var xhr = new xmlhttprequest();   xhr.open("get", url,  false );   xhr.send();   return xhr.responsetext; }  var response = json.parse( get( url ) ); if( response.status ) alert( "matches found" ); else alert( "no matches" ); 

php:

header( 'content-type: text/json' ); if( get_matches( $_get['userinput'] ) ) exit( '{ "status": true }' ); else exit( '{ "status": false }' ); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -