I want to post json output to a new window. How could I achieve this? Thank You!
Here is my code:
function onSuccess(data, status)
{
data = $.trim(data);
$("#notification").text(data);
}
$(document).ready(function() {
$("#submit").click(function(){
var formData = $("#callAjaxForm").serialize();
$.ajax({
type: "POST",
url: "callajax.php",
cache: false,
data: formData,
success: onSuccess,
error: onError
});
return false;
});
});
</script>
<form id="callAjaxForm">
<div data-role="fieldcontain">
<label for="firstName">First Name</label>
<input type="text" name="firstName" id="firstName" value="" />
<label for="lastName">Last Name</label>
<input type="text" name="lastName" id="lastName" value="" />
<button data-theme="b" id="submit" type="submit">Submit</button>
</div>
</form>
and below is callajax.php (I want to show the json information on this page)
<?php
$fName = $_POST['firstName'];
$lName = $_POST['lastName'];
echo("First Name: " . $firstName . " Last Name: " . $lastName);
?>
if you want to make a JSON representation of the data you are sending from the form use:
<?php
$fName = $_POST['firstName'];
$lName = $_POST['lastName'];
$resp = array('first_name'=>$fName,'last_name'=>$lName);
echo json_encode($resp);
?>