Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Clearing Last JSON Response

$
0
0

I am developing an iOS 6.1 app using Titanium Studio, build: 3.1.2.201307091805, testing on the iPhone simulator and iPad device. I have a search field that gets JSON results from a remote server. The screen I am having issues with has the search box at the top and a couple of messages below. When the user types in the search field and hits return, the messages are hidden and a table is placed ready to receive the results from the database. All of that is working fine. When the user types in something that is not in the database I have a message appear "No results found, please try again". I made a button to "Clear" the table or "Not Found" message. Here is the button code I have so far:

var clear = Ti.UI.createButton({
    title: "Clear",
    style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
});
clear.addEventListener("click", function() {
message.hide();
table.setData([]);
});
Ti.UI.currentWindow.setRightNavButton(clear);
This code does clear the message or the results in the table but when I do another search the previous result appears above the new result even if the searches were totally unrelated. Here is how I am getting my data.
var table = Ti.UI.createTableView({
    backgroundColor: 'transparent',
    top: '0dp',
    height:'auto',
    bottom:'0dp'
});
table.show();
 
var tableData = [];
function checkInternetConnection(){
return Ti.Network.online ? true : false;
}
customSearchField.addEventListener("return", function(e) {
 
    if(checkInternetConnection()){
    nolist.hide();
    businessowner.hide();
    view.add(table);
    getdata();
win.add(view);
 
function getdata(){
var url = "http://mydomain.com/hville/filename.php?title="+e.value;
 
var xhr = Ti.Network.createHTTPClient({
    onload: function() {
    Ti.API.debug(this.responseText);
 
var json = JSON.parse(this.responseText);
... rest of the code ...
If I press my back button and then return to this screen, the search is fine. How can I completely clear the previous results without leaving the screen and then returning?

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>