http://Bj83.de

Json Calls with Jquery

The calling html part:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="test.js" type="text/JavaScript"></script>
<form onsubmit="" action="" method="POST" name="myform">
    <input type="hidden" name="paramvalue" value="testvalue" id="paramvalue"/>
    <input type="button" onclick="javascript:getData()" value="Generiere Ausgabe"></input>
</form>
<div name="dummy" id="dummy"></div>

the running javascript

function getData(){
    if (document.getElementById('paramvalue')) {
			var fldparam = document.getElementById('paramvalue');
			param = fldparam.value;
			var sap_data = document.getElementById('dummy');
			sap_data.innerHTML = param;
			
			$.getJSON( "test.php", function( data ) {
				alert(data);
			});
	}
}

the value generating php

<?PHP
    set_time_limit ( 60 );	//prevents timeouts
	echo json_encode('Hello World');
?>

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: