Qt Webkit - browser interaction issue

I am developing a Qt program containing an OpenStreetMap application in the form of an HTML page, and this page has access to the -via database, which is an ajax form that contains the start and end dates of the requests, to retrieve and visualize the requests on the map. I would like to move this request process to Qt from the HTML / Javascript part. So far I have been able to interact with the browser through Qt, but I still have a problem that is lower:

1) Click the Qt fetch request button and a warning window will appear saying that AJAX POST is not working - the database is not on my current laptop and I should get an error when I click either the HTML Request button to select the browser window or Qt selection button -

2) But also, whenever I click the "Fetch Requests" button in the HTML browser, it displays a POST warning, and also displays additional POST warning messages, depending on how many times I clicked the Qt Fetch queries button. for example, if I clicked the Qt fetch request button 5 times in a row, and then once clicked the HTML window select button, I get 6 POST error messages in a line -

The HTML code is as follows:

<form id="ajaxForm" action="index.php" method="post">
Start <input type="text" name = "date1" id = "datepicker" value = "2011-07-13" style = "width:70px">
<input type="text" name = "time1" id = "timepicker1" value = "00:00" style = "width:40px"> 

End <input type="text" name = "date2" id = "datepicker2" value = "2011-07-13" style = "width:70px">
<input type="text" name = "time2" id = "timepicker2" value = "00:01" style = "width:40px">

The post-method of the AJAX form is as follows:

<script type="text/javascript">

$(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;
 });
});

</script>

And finally, the Qt code calling the function is as follows:

void MainWindow::onButtonClicked() // clicking the button in order to POST 
{
    //the QString a is the same ajax post function as declared above

    QString 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);

}

Any ideas on what's wrong here? Thank.

+3
source share
1 answer

I think I have a problem. XMLHttpRequestloads your local file successfully, but returns 0to request.status, so it error()starts from your jQuery code.

QWebView..

var request = new XMLHttpRequest();  
request.open('POST', 'file:///C:/hello.txt', true);

request.onreadystatechange = function(e) {  

    if(request.readyState == 4)
    {
        // 'responseText' will not be empty if file present..
        alert("response text: " + request.responseText);
        alert("status: " + request.status);
    }
}

request.send();

, .

+3

All Articles