On the computer, the request is executed perfectly, but not from the smartphone. It is about requesting AJAX with the subsequent creation of elements and adding these elements to the page.
I understand that I am absolutely green in this matter (programming) and may not know the basic things, but I ask for help (googled but did not find a solution).
Task: Search for products from the database;
Structure: when typing in the input, JQUERY tracks the change and makes an AJAX request a request to the server via PHP and SQL, we get a list of suitable products. JQUERY receives a list and creates a new DIV block for each element and loads it into the page.
PROBLEM: It works on the computer, but if I type the text from SMARTPHONE, there is no result.
Link to the working site: http://wo-market.com
SCRIPT:
$('#searchText').keypress(function (){ if(event.keyCode==13){ var findText = $('#searchText').val(); if(findText.length>=3){ location.href = '/product/show/'+findText+'/'; $("#searchResult").remove(); } }else{ var findText = $('#searchText').val(); if(findText.length>=3){ $("#searchResult").remove(); $("#searchBar a").attr('href','/product/show/'+findText+'/'); findProductsByFindText(findText); };} }); / ** * Product Search * * /
function findProductsByFindText(findText){ var findT = findText; var findText = "findText=" + findT; $.ajax({ type:'POST', async:true, url:"/product/find/", data: findText, dataType:'json', success: function(data){ if(data){ console.log(" 1 - " + findText + " :: " + data); resultProductsFromFindText(data); } else { return 0; } } }) } / ** * Advertise product under Input Search * * /
function resultProductsFromFindText(res){ var resData = res; var searchField = document.getElementById("searchBar"); var searchResult = document.createElement('div'); searchResult.setAttribute("id", "searchResult"); searchField.appendChild(searchResult); for(i=0;i<resData.length;i++){ searchResult.appendChild(addProduct(resData[i])); } } / ** * Creating a product item from a search * * /
function addProduct(i) { var i = i; var div = document.createElement('div'); div.innerHTML = '<a href="/product/' + i['id'] + '/">' + i['name_ru'] + '</a><a href="/product/' + i['id'] + '/"><img src="/images/products/' + i['image']+ '" width=50 height=50 /><a><br />' ; div.setAttribute("class", "searchProduct"); return div; } ;