, , AJAX , . modal.load, POST , .
, AJAX , HTML HTML DIV , SimpleModal DIV.
, = "button" type = "submit". . , event.preventDefault(); false submit click handler (. ), , , :
1:
<input id="searchquestion" name="searchQuestion" type="button" value="Search" />
2:
, serializeArray . HTML HTML. , , :
$('form[type="button"]').click(function() {
var dataString = $('form').serializeArray();
$.ajax({
url: "/previousquestions.php?t="+new Date().getTime(),
type: "POST",
data: dataString,
context: document.body,
success: function(data){
alert(data);
$('simplemodal-data').html(data);
},
error: function(jqXHR, textStatus, errorThrown) {
if(window.location.hostname == "localhost") {
alert("Error submitting the form :: " + textStatus + " : " + errorThrown);
}
console.error("Error submitting the form :: " + textStatus + " : " + errorThrown);
}
});
});
3:
Finally, make sure that your code previousquestions.phpreturns only a partial HTML document, not a full HTML document. Since you are embedding HTML in an existing page, you do not need sections <html>, <head>or <body>. This will cause your page to not be checked and may lead to unwanted behavior in older browsers. Here is an example of what your answer might look like:
<div id="previouslink">
<button type="button" id="close" onclick="return closewindow();">Close</button>
<h1>PREVIOUS QUESTIONS</h1>
<p>Search for a previous question by entering in a phrase in the search box below and submitting the phrase</p>
<form action="previousquestions.php" method="post">
<p>Search: <input type="text" name="questioncontent" value="test" /></p>
<p><input id="searchquestion" name="searchQuestion" type="submit" value="Search" /></p>
</form>
</div>
<p>
Your Search: 'test' </p>
<p>Number of Questions Shown from the Search: <strong>0</strong></p><p>Sorry, No Questions were found from this Search</p>