打开一个jQuery ui对话框,并在表单提交后显示PHP Post响应
问题描述:
I have a jQuery based form which set a value of an hidden input field in a form. I retrieve this value after a form submit with php : $_POST['myinputvar'] (it's a generated url).
This retrieved var is an url to a XML file which I parse with SimpleXML function.
The goal is to display this result in a dialog box after the submission of the form and do my PHP stuff here
The code :
the jQuery to populate my input field :
$('#myForm').submit(function() {
$("input[name='field']").val(generatedUrl);
});
The PHP :
if (isset($_POST['field']))
{
$xml = simplexml_load_file($_POST['field']);
print_r($xml);
}
The form :
<form action="http://www.mysite.com/index.php" id="myForm" method="post">
<input name="field" type="hidden" value='' />
<input id="submit" type="submit" value="ok" />
</form>
So how can I display my PHP part into a dialog box after submit?
Any help will be very appreciated! Thanks!
答
Since it seems you don't use AJAX, you can do it that way as statued in the doc :
<script>
$(function() {
$( "#dialog" ).dialog();
});
</script>
<div id="dialog" title="Basic dialog">
<p><?php echo $xml;?></p>
</div>