Qt Webkit - Browser Interaction issue [SOLVED]
-
Hello everyone, I'm developing a Qt program that contains an OpenStreetMap application as a HTML page and this page is able to access a database (via submitting an ajax form that contains the start and end dates of queries) in order to retrieve and visualize queries on the map. I would like to move this querying process to Qt from the HTML/Javascript part. So far I managed to interact with the browser via Qt but I still have a problem that is below: (by the way, the database is a MySQL database on XAMPP and trying to fetch queries from the HTML window's fetch button works -although it also sometimes shows the POST failed message and then clicking again fetches and shows the queries correctly, I haven't been able to figure that out either)
-
The fetch queries button of Qt is clicked and an alert box is supposed to pop up saying that Ajax POST is failed (the database is not on my current laptop and I should be getting the error when I click either the HTML Browser window's fetch queries button or the Qt's fetch button)
-
But also, whenever I click the Fetch queries button of the HTML Browser, it displays the POST warning but also displays extra POST warning alert boxes depending on how many times I have clicked the Qt's Fetch queries button. (for example if I have clicked the Qt's fetch queries button 5 times in a row and then clicked the HTML window's fetch button once, I get 6 POST failed messages in a row, I just want the queries to be displayed when I click Qt's fetch button instead of HTML's fetch button)
The HTML code is like the following:
@<form id="ajaxForm" action="index.php" method="post">
Start <input type="text" name = "date1" id = "datepicker" value = "2011-07-13" >
<input type="text" name = "time1" id = "timepicker1" value = "00:00" >End <input type="text" name = "date2" id = "datepicker2" value = "2011-07-13" >
<input type="text" name = "time2" id = "timepicker2" value = "00:01" >@The post method of AJAX form is this:
@
$(document).ready(function(){// ajaxForm submit
$('#ajaxForm').submit(function() {
$.ajax({
type: 'POST',
url: 'heatQuery.php',
data: $(this).serialize(),
dataType: 'json',
success: function(response)
{
// update the points for heatmap layer
updateHeatMap(response);},
error: function(errorMsg)
{
alert('Error in Ajax POST');
}
});return false;
});
});@And the Qt code that calls the function is this:
@void MainWindow::onButtonClicked() // clicking the button in order to POST
{
//the QString a is the same ajax post function as declared aboveQString a = "$(document).ready(function(){$('#ajaxForm').submit(function() {$.ajax({type: 'POST',url: 'heatQuery.php',data: $(this).serialize(),dataType: 'json',success: function(response){updateHeatMap(response);},error: function(errorMsg){alert('Error in Ajax POST');}});return false;});});"; this->view->page()->mainFrame()->evaluateJavaScript(a);
}@
Also, the heatQuery.php and theHeatmap.html files are in the D:/xampp/htdocs folder since server runs them. And finally, I have initialized the WebView as
@view->load(QUrl("http://localhost/theHeatmap.html"));@
What is wrong here? Thanks.
-
-
@$(document).ready(function(){...});@
will be called when document completely loaded. So, if your document is loaded, and you add this javascript code after that, $(document).ready will be not called again.
if you want submit your form. just call $('#ajaxForm').submit()
-
[quote author="AcerExtensa" date="1337763304"]
@$(document).ready(function(){...});@will be called when document completely loaded. So, if your document is loaded, and you add this javascript code after that, $(document).ready will be not called again.
if you want submit your form. just call $('#ajaxForm').submit()
[/quote]
I have been messing with that error for the past three days or so and you saved me from a big trouble. I can't thank you enough, now everything works..
-
I'am glad i can help you! Please add "[SOLVED]" to the topic subject.