Posts

Showing posts with the label ajax

Session content not being deleted with either session_destroy(); or unset

Session content not being deleted with either session_destroy(); or unset I've had this issue for a couple of days and I can't seem to fix it whatever I try. There is a loginform that either redirects you to /dashboard or /admin depending on the data that is in the started session from my loginscript. /dashboard /admin This is my structure: index.php (contains header with connection.php and the html login form) dashboard.php (contains header with connection.php and some irrelevant html) admin.php (same as above) header.php (at the top of all pages, has connection.php included at the first line). connection.php (my connection script, with at the top line session_start(); login.php (my loginscript, this script is called with ajax so I have to add my entire connection class in here with session_start(); again at the top. logout.php (my logout script, it kills the session and redirects to login page this is linked to in my header.php) In my loginscript I have the following part: ...

Load Random Images from Directory

Load Random Images from Directory I'd like to randomly load images from a directory and have a button somewhere that refreshes the entire page. Here's the current code I have now: <?php $a = array(); $dir = '../public/wp-content/uploads/2012/01'; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if (preg_match("/.png$/", $file)) $a = $file; elseif (preg_match("/.jpg$/", $file)) $a = $file; elseif (preg_match("/.jpeg$/", $file)) $a = $file; } closedir($handle); } foreach ($a as $i) { echo "<img src='" . $dir . '/' . $i . "' />"; } ?> The problem is it loads all 400,000 images at once. I only want 30 to load. 30 random images from the directory. I tried looking up some code such as modifying the above to this: <?php $a = array(); $dir = '../public/wp-content/uploads/2012/01'; if ($handle = opendir($dir)) { while (false !== ($file = re...

The filemtime () isn't working for my script, but is working fine for the script where I copied the example code

The filemtime () isn't working for my script, but is working fine for the script where I copied the example code I have a .txt file located under some folder of my data files. Now I have created a long polling system ( actually copied the code ) which is run by ajax. Now the problem is that my php script is unable to fetch file modification time of the text file (it totally disregards the file). Below I have both the original code of the author and my twerked code. The one of the author worked fine, but not mine. Plz help. The apache server is hosted on windows server THe file path is absolutly correct and file exist. Here's the section of my code which has error while (true) { //**The error occurs here** $fileModifyTime = filectime($file); if ($fileModifyTime === false) { throw new Exception('Could not read last modification time'); } // if the last modification time of the file is greater than the last update sent to the browser... ...

Passing data from java file to ajax

Passing data from java file to ajax I have a java class printing the progress of a process as 1%, 2%, 3%. Now I want to read this progress using AJAX requests and continuously update the progress in the webpage. I cannot convert the java file into a servlet as it is being used as an scriptlet by Jasper. Scriptlet code is : public void afterDetailEval() throws JRScriptletException{ count = (Integer) this.getVariableValue("count"); out.println(count); Thread.sleep(200); } How can I read the data printed by java from an AJAX request? Any help will be greatly appreciated! What do you think about your choice to not show the code you have that's doing the stuff you just described, while also asking for help about just these things? – kumesana Jul 1 at 20:07 what is your java class running ...

Ajax/jQuery autocomplete in search box (Shopify)

Ajax/jQuery autocomplete in search box (Shopify) I am looking to get autocomplete setup on my search bars within my Shopify shop- this uses Liquid and ajax I found this tutorial, and implemented it as it says, however it is not working, nothing gets autocompleted on any search bar on the site- I think it may be quite old and was written before the updates/changes to Minimal/Shopify search functionality. https://help.shopify.com/themes/customization/store/enable-autocomplete-for-search-boxes I can follow it through with Chrome dev tools, and it seems like it gets stuck where it adds the search-results list $('<ul class="search-results"></ul>').appendTo($(this)).hide(); , this doesn't appear when tracing the HTML of the page. This means that when it later tries to find this list var resultsList = form.find('.search-results'); it doesn't find it, and thus cannot populate with items. $('<ul class="search-results"></ul...

How to read JSON file from folder project ASP.NET

Image
How to read JSON file from folder project ASP.NET I create a folder "js" inside Script folder and create a file json with array citys and i try read this file on this folder and return a list to my select view. { "cidade": [ { "Nome": "Curitiba" }, { "Nome": "São Paulo" }, { "Nome": "Rio de Janeiro" }, { "Nome": "Santa Catarina" }, { "Nome": "Rio Grande do Sul" }, { "Nome": "Acre" }, { "Nome": "Goias" } ] } My class: public class Cidade { public string Nome { get; set; } } public class Cidades { public IList < Cidade > cidades { get; set; } } And my action : public class Cidade { public string Nome { get; set; } } public class Cidades { public IList < Cidade > cidades { get; set; } } This is the error: What is...

how can i fetch the people i follow but they don't follow back?

how can i fetch the people i follow but they don't follow back? so i have a table called follow_sys with three columns id and follower and following containing the usernames of followers and followed ,so i want to fetch all of the followers i follow but they don't follow me back, how can i do that ? follow_sys id follower following i tried a self join but it didn't work, i'm confused $sqlFollowing = "SELECT * from follows_syds t1 join follows_syds t2 on t1.follower != t2.following where t1.follower = ? group by t1.id"; $Following = $conn -> prepare($sqlFollowing); $Following -> bind_param('s',$getUser); $Following -> execute(); $FollowingGET = $Following -> get_result(); $FollowingRows = $FollowingGET -> num_rows; while($b = $FollowingGET -...

Servlet doesnt write JSON Output to AJAX

Servlet doesnt write JSON Output to AJAX Following code for my output: PrintWriter out = response.getWriter(); ObjectMapper objectMapper = new ObjectMapper(); ToJson obj = new ToJson(); String obj1 = objectMapper.writeValueAsString(obj); response.setContentType("application/json"); out.print(obj1); System.out.println(obj1); out.close(); The obj1 looks like this: {"prname1":"P1neu","anz1":"342356","prid1":"1","price1":"25"} {"prname1":"P1neu","anz1":"342356","prid1":"1","price1":"25"} It should send the string out so I can parse it in my AJAX and display it but somwhow it ends up with nothing as console.log/etc doesnt display any data. I had out.append but it also didnt work. out.append 1 Answer 1 ...

why can't we use async:true in loop?

why can't we use async:true in loop? I have gone through the question Javascript - AJAX request inside loops. I understood the question and answer. var totalQuotes = 1; var url = http://whisperingforest.org/js/getQuote(1).php; var amount =0; var sum = 0; var bookingAmount = 0; while (counter < 6) { $.ajax({ url:url, async: false, dataType: 'json', success:function(data) { jQuery.each(data, function(index, item) { amount = amount + item.amount; sum = sum + item.sum; bookingAmount = bookingAmount + item.bookingAmount; }); $('.amount').val(amount); $('.sum').val(sum); $('.bookingAmount').val(bookingAmount); } }); totalQuotes++; url = "http://whisperingforest.org/js/getQuote(" + totalQuotes + ").php"; counter++; } In above code why can't we use async:true ? What will...

Success part of a function does not work

Success part of a function does not work I have two input with type text, and I wrote a function onkeyup when the user starts to write somthing I send my data to another page that is called "jsonpage.html". but the success part of my code does not work. I Think it cannot find the address of divs . but at first part it could find it. I don't have any idea that why it doesn't work in success part ? if you omit part "$(this).closest(".main").find" fro success it works .but after i add these lines it does not . here is my snippet : $('.country').each(function() { $(this).on('keyup', function(e) { var element = $(this).val().length; if (e.which !== 0 && !e.ctrlKey && !e.metaKey && !e.altKey ) { if (element > 2) { $(this).closest(".main").find(".mini-loading").css("display", "block") var val = ...

Ajax success function with python: odd behavior

Ajax success function with python: odd behavior I found an odd behavior when trying to use data on the browser-side, which is sent by a python script client-side. The ajax call is: $.ajax({ async: true, type: "POST", url: "/path/cgi-bin/pyscript.py", data: JSON.stringify(my_array), dataType: "html", success : function(data) { document.getElementById("ajaxAnchor").innerHTML = data + "Some random string to test display" } }); } I wanted to send back to data the result of a print() in the python script, but this only works in an unusually specific case. For the printed data to be sent back, there must first exist a print() executed with an n at the end. data print() print() n print("This line won't be sent to browser but is necessary n") print("This text will be sent back") And it's not just about adding the line break, because the following example won't work: ...

toDataURL's output is base64, how to reduce the uploading time and bandwidth of a factor 1/3?

toDataURL's output is base64, how to reduce the uploading time and bandwidth of a factor 1/3? The goal of the following code is to compress the input file (2 MB JPG file => 500 KB file) and then upload it to server when submitting the <form> . <form> When importing an image from a JPG file into a canvas, and exporting it with toDataURL with: toDataURL function doit() { var file = document.getElementById('file').files[0], canvas = document.getElementById('canvas'), hidden = document.getElementById('hidden'), ctx = canvas.getContext("2d"), img = document.createElement("img"), reader = new FileReader(); reader.onload = function(e) { img.src = e.target.result; } img.onload = function () { ctx.drawImage(img, 0, 0); hidden.value = canvas.toDataURL("image/jpeg", 0.5); } reader.readAsDataURL(file); } <input type="file...

fullcalendar ajax success does not working

fullcalendar ajax success does not working I am making reservation website using fullcalendar. I insert event into my DB using Ajax. However, the problem is that success function was not working, but every data was successfully inserted into DB. Also I changed success to error, but still nothing happened. Here is code where I insert event into DB select: function(start, end, allDay) { var teacher = prompt("Enter ResourceID"); if(teacher) { var start = $.fullCalendar.formatDate(start, "Y-MM-DD HH:mm:ss"); var end = $.fullCalendar.formatDate(end, "Y-MM-DD HH:mm:ss"); $.ajax({ url:"http://show981111.cafe24.com/login-system/addevent.php", type:"POST", data:{userName: '<?php echo $name; ?>' , newlyBookedDate:start, courseTeacher : teacher, userBranch:'<?php echo $userBranch; ?>', userID: '<?php echo $userID; ?...