JavaScript - ['resolved']ajax Problem, Responsetext Is Blank
Edit: Nevermind
Similar TutorialsDear Forum Guys, I have a problem regarding how to recieve multiple response texts from an Ajax code. That is: I want to recieve multiple "responseText"s from the ajax code so that i can populate my form in an asp page. I would also like to know how i can send multiple asp or javascipt Variables inside the responseText of an Ajax code, so that when ajax does responseText i could use the variables just sent from another page (i.e the variables are recieved by the same ajax code after doing responseText) to do some specific tasks. Thank you. AJAX XMLHttpRequest responseText returns undefined but alert returns expected text. Code: function getFile(fileToOpen) { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Your browser does not support XMLHTTP!"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState==4) { //alert(xmlhttp.responseText); return xmlhttp.responseText; } } xmlhttp.open("GET",fileToOpen,true); xmlhttp.send(null); } Code: document.getElementById('widgetOptionsShadow').innerHTML = '<div id="widgetOptions">' + getFile('/togglePauseInit.php?g=<?php echo $gadgetName; ?>') + '</div>'; Hello guys, i really need help with my code...i was stuck with it for like 4 hours >< I want to display the content of my text file inside the html page in the div tags so i could place it somewhere around th page or change it style etc. Could anyone please help? And another question : Are there any chances to display my text data, which is one number in the input box ? Quote: <HTML><HEAD> <SCRIPT language = "Javascript"> objXml = new ActiveXObject("Microsoft.XMLHTTP"); var datafile = "G:\data.txt"; objXml.open("GET", datafile, true); objXml.onreadystatechange=function() { if (objXml.readyState==4) { display(objXml.responseText); } } objXml.send(null); function display(msg) { mydiv.innerHTML = msg ; } </SCRIPT> <BODY> <input type='button' onclick='display(msg)' value='Display'/> <div id="mydiv"></div> </BODY> </HTML> hi, When I navigate to a page with Ajax on my iphone or ipad, it doesn't show up, page is just blank, I have checked for errors and there is no errors?! here is my Ajax code Code: function datecheckFunction(){ var datecheckRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari datecheckRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ datecheckRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ datecheckRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server datecheckRequest.onreadystatechange = function(){ if(datecheckRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = datecheckRequest.responseText; } } var datepicker = document.getElementById('datepicker').value; var queryString = "?datepicker=" + datepicker; //Add the following line datecheckRequest.open("GET", "http://www.affordableappliancerepairs.co.uk/admin/checkdate.php" + queryString, true); datecheckRequest.send(null); } I have this script which is set to generate random anagrams of my name in rotation which works fine, but I can't work out how to put multiple instances of it on one page. if someone could point me in the right direction i'd be very grateful. thanks the code is var quotations = new Array() quotations[0]= "germaine arnold" quotations[1]= "endearing moral" quotations[2]= "analog reminder" quotations[3]= "regained normal" quotations[4]= "renaming ordeal" quotations[5]= "nominal regrade" quotations[6]= "arraigned lemon" quotations[7]= "ringleader moan" quotations[8]= "mineral groaned" function display() { a=Math.floor(Math.random()*quotations.length) document.getElementById('quotation').innerHTML=quotations[a] setTimeout("display()",5000) } and i'm calling the function using: <div id="quotation"> <SCRIPT type="text/javascript">display()</SCRIPT> </div> RESOLVED Thank you! Greetings all! Im looking for some help regarding responseText, so please have a look im so mad right now because i have been struggeling for hours XMLHttpRequestObject.responseText returns correct value when i do alert(XMLHttpRequestObject.responseText); see line PHP Code: var fnWhenDone = function (XMLHttpRequestObject) { alert(XMLHttpRequestObject.responseText); }; But problem is that i want to save down the response to a variable... so i try to change it into PHP Code: var fnWhenDone = function (XMLHttpRequestObject) { varTest = XMLHttpRequestObject.responseText; }; When i try to alert varTest later i get "Undifined"... im pretty new to javascript and have been stuck for hours ... See full code below PHP Code: var myConn = new XHConn(); if (!myConn) { alert("XMLHTTP not available. Try a newer/better browser."); } var fnWhenDone = function (XMLHttpRequestObject) { alert(XMLHttpRequestObject.responseText); }; myConn.connect("validateSearch.php", "POST", "foo=bar&baz=qux", fnWhenDone); function XHConn() { var xmlhttp, bComplete = false; try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; }}} if (!xmlhttp) return null; this.connect = function(sURL, sMethod, sVars, fnDone) { if (!xmlhttp) return false; bComplete = false; sMethod = sMethod.toUpperCase(); try { if (sMethod == "GET") { xmlhttp.open(sMethod, sURL+"?"+sVars, true); sVars = ""; } else { xmlhttp.open(sMethod, sURL, true); xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1"); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); } xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4 && !bComplete) { bComplete = true; fnDone(xmlhttp); }}; xmlhttp.send(sVars); } catch(z) { return false; } return true; }; return this; } I am wondering how can I return the variable senttext from the function below? I have declared it and when I alert(senttext) below it appears as I want it but I need to return it and pass it to another function. When I change alert() to return the variable becomes undefined??? var senttext; function getData() { if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } req.open('GET',"http://www.site6.certcoordering1.com/Download/recall.txt" ); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.status == 200) { senttext ='<table style="border:thin black solid"><tr><td><h2>Recent</h2></td><td><h2>Recalls</h2></td><td></td><td></td></tr>' ; var ad2 = req.responseText.split("\n"); for(i=0; i<ad2.length-1; i++) { // now split by comma var ad3 = ad2[i].split(","); senttext += '<tr><td><p>'+ad3[0]+'</p></td><td> <a href="http://www.site6.certcoordering1.com/Download/'+ad3[2]+' rel="nofollow" target="_blank">'+ad3[1] +'</a></td><td></td></tr>' } senttext += '</table>' ; alert(senttext); // I need to return senttext, not alert! When I send it it becomes undefined? } else { alert('File did not load correctly.'); } } } req.send(""); } hi everyone.. i am using ajax to change the banner background while pressing on refresh Note:it must be a background image because i will display data from database... http://www.graphicano.com/isis/nile_crown2.php please look at this link... my problem is: when i press refresh button in Firefox browser it changes the background and on pressing refresh again the background will change but in internet explorer 8.0 it changes the background only for the first time and on pressing refresh again the background will not change. how i can fix this problem ?? i want the user to press refresh at any time and the background will change.. not only for the first time? at the same time it must be a background image because i will display text from database... I have the following ajax code: Quote: ............. ............. ............. XHR.createXMLHttp(); XHR.open("POST", "/cgi-bin/addpost.cgi", true); XHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); XHR.onreadystatechange = function() { if (XHR.readyState == 4) { if (XHR.status == 200) { alert("Operazione effettuata con successo"); } else { alert("Operazione non riuscita"); } } } XHR.send(url); The function send data, but it don't return never alert windows. Where is the problem? Hello, Currently, i am working on a website. I need that when the data comes from ajax in the div or span tag, it should take space by moving down the data already present there without overwriting it. But it doesnot happens. When i get data through ajax, then it overwirtes the previous data which was already present there and doesnot move the previous data downwards. Any help plz Hi Chaps, I'm trying to get a AJAX script to work, but am having problems. I have a page with two dropdown menus, the idea is that the first dropdown [customers] will then filter the options of the second [contacts]: //DROPDOWN.PHP PHP Code: <form method="post" action=""> <select name="customer" onChange="ContactGrab('."'".'ajaxcalling.php?id='."'".'+this.value);"> <option value="">Select Customer</option> <?php do { ?> <?php echo "<option value=".'"'.$row_rsCustomer['custid'].'" >'.$row_rsCustomer['custname']."</option>";?> <?php } while ($row_rsCustomer = mysql_fetch_assoc($rsCustomer)); $rows = mysql_num_rows($rsCustomer); if($rows > 0) { mysql_data_seek($rsCustomer, 0); $row_rsCustomer = mysql_fetch_assoc($rsCustomer); } ?> </select><br /> <div id="details"> <select name="details"> <option value="">Select Contact</option> <?php do { ?> <option value="<?php echo $row_rsContact['contactname']?>"><?php echo $row_rsContact['contactname']?></option> <?php } while ($row_rsContact = mysql_fetch_assoc($rsContact)); $rows = mysql_num_rows($rsContact); if($rows > 0) { mysql_data_seek($rsContact, 0); $row_rsContact = mysql_fetch_assoc($rsContact); } ?> </select> </div> </form> The OnChange action should call the AJAXCALLING.PHP page, where the other select options are filtered, by column [FK_custid] //AJAXCALLING.PHP PHP Code: <select name="details"> <option value="">Select Contact</option> <?php do { ?> <option value="<?php echo $row_rsContact['contactid']?>"><?php echo $row_rsContact['contactname']?></option> <?php } while ($row_rsContact = mysql_fetch_assoc($rsContact)); $rows = mysql_num_rows($rsContact); if($rows > 0) { mysql_data_seek($rsContact, 0); $row_rsContact = mysql_fetch_assoc($rsContact); } ?> </select> This is powered by the AJAXSCRIPT.JS page Code: function CreateXmlHttpObject() { //fuction to return the xml http object var xmlhttp=false; try{ xmlhttp=new XMLHttpRequest();//creates a new ajax object } catch(e) { try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");//this is for IE browser } catch(e){ try{ req = new ActiveXObject("Msxml2.XMLHTTP");//this is for IE browser } catch(e1){ xmlhttp=false;//error creating object } } } return xmlhttp; } function CategoryGrab(strURL) { var req = CreateXmlHttpObject(); // fuction to get xmlhttp object if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { //data is retrieved from server if (req.status == 200) { // which reprents ok status document.getElementById('details').innerHTML=req.responseText;//put the results of the requests in or element } else { alert("There was a problem while using XMLHTTP:\n"); } } } req.open("GET", strURL, true); //open url using get method req.send(null);//send the results } } My problem is that when I open the dropdown.php page, the browser status says 'Done, but with errors on the page' and the second dropdown isn't filtering. I can get rid of the status warning by removing: Quote: ...onChange="ContactGrab('."'".'ajaxcalling.php?id='."'".'+this.value);"> But obviously that is something that is needed to pass the [custid] in the URL parameter.... Can anyone help me on this, as I haven't got a clue what I'm missing or where I have gone wrong! Firstly I apologize if this is the wrong forum, I wasn't too sure of where to post it as my problem covers several areas. I have been writing a 'Facebook Application' which is primarily in PHP. It is about the economics of futuristic spaceship production. I have done the bulk of the game mechanics in PHP and have set about making the interface. I am stuck on a page which can be viewed here where you can employ workers to work in your mines/factories. Each worker has five skill types (worker, miner, manager etc...) and to be employed he must be offered a contract for one of those skills. The process of employing someone works like this. 1. You search for the 'type' of worker you want. 2. Search Results are shown. 3. You click on the name of the person you want to employ. 4. A new form appears (under the table) for you to fill in the contract details. 5. The person (PHP function!) rejects or accepts the contract. If you look at the link above you will see I've made a search box which uses AJAX/html/php to make the table (which I'm quite proud of as I'm a bit of a noob when it comes to javascript/ajax). Ive come unstuck as to how to select which worker to offer a contract to. What needs to happen is: 1. The name or a tick box is selected. 2. It sends some form of unique identifier back to the same page so the form (to offer a contract) knows which person in the table is being referred to *preferably without a page refresh*. Any help/advice would be greatly appreciated. I'm assuming I'm going to need to use some form of get/post and ajax but i cant figure out how to do it. I hope all this makes sense. I'm a newbie so excuse me if question could be stupid I have a webpage where i have placed a form html with recaptcha validation I have grabbed on the net following code : Code: Code: <script type="text/javascript"> function validateCaptcha() { challengeField = $("input#recaptcha_challenge_field").val(); responseField = $("input#recaptcha_response_field").val(); //alert(challengeField); //alert(responseField); //return false; var html = $.ajax({ type: "POST", url: "http://mysite.com/script.php", data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField, async: false }).responseText; if (html.replace(/^\s+|\s+$/, '') == "success") { $("#show").html("Success. Submitting form."); return false; // Uncomment the following line in your application //return true; } else { $("#show").html("Your captcha is incorrect. Please try again"); Recaptcha.reload(); return false; } } </script> and form html: Code: Code: <form action="#" method="post" onSubmit="return validateCaptcha()"> <p><?php echo recaptcha_get_html($publickey);?></p> <p style="color: red;" id="show"> </p> <input type="submit" name="Submit" value="Submit"> </form> On the file: script.php i have placed php code: PHP Code: PHP Code: <?php require_once('controllers/recaptchalib.php'); $privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; # was there a reCAPTCHA response? { $response = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$response->is_valid) { echo 'ERROR: The recaptcha code was not entered correctly or expired.'; die; } else echo "success"; } ?> the code work but i don't want display in my webpage only messages: "Your captcha is incorrect. Please try again" if code is incorrect and "Success. Submitting form." if code is correct. But if the code is correct i want display under sentence "Success. Submitting form." the content of script.php ie print a table or whatever script contain obviously without reloading webpage or redirect to another page How to? thanks Right i'm having trouble with a Ajax refresh external page script. Code: <script type="text/javascript"> function Ajax() { var $http, $self = arguments.callee; if (window.XMLHttpRequest) { $http = new XMLHttpRequest(); } else if (window.ActiveXObject) { try { $http = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { $http = new ActiveXObject('Microsoft.XMLHTTP'); } } if ($http) { $http.onreadystatechange = function() { if (/4|^complete$/.test($http.readyState)) { document.getElementById('ReloadThis').innerHTML = $http.responseText; setTimeout(function(){$self();}, 1000); } }; $http.open('GET', 'stats.php' + '?' + new Date().getTime(), true); $http.send(null); } } </script> <script type="text/javascript"> setTimeout(function() {Ajax();}, 1000); </script> <div id="ReloadThis"> Loading.... </div> That's what i'm currently using, but everytime it refresh's it well, i've got a marquee in the stats.php file & i want it to refresh every second but the marquee jumps back to the right and starts again i want a Ajax script that dont affect the external data that load's like facebook does. Can anyone help? Thanks... i have used a an ajax xml ticker script in my webpage here's the link to the page where i got the script : http://www.dynamicdrive.com/dynamicindex2/cmarquee2.htm The problem is as soon as it reaches the end of the content, It does not cycle up to the first news item immediately there is a gap of few seconds before starts showing the items again. All, I am trying to create a page for a application that uses a technique where a page refresh is generated by an ajax call followed by an innerhtml replace on the main page div. Unfortunately this strange way of refreshing pages is leading to an issue with an image I am trying to display. Every time it refreshes the images flashes off and then is redisplayed, there are other elements on the page( smaller images, text etc... ) and they do not seem to be affected. The image is not large, only 23 k, but it is the only one affected. If I run the page on firefox I do not encounter this issue which makes me think that is a lovely IE feature that forces the image to be retrived from the server on every innerhtml replace instead of from the cache. I am using IE8 to test this, any suggestions are greatly appreciated as I have been trying to fix this for a while. Thanks, N Dear forum guys, I'm having a problem regarding the POST method with Ajax. I'm sending form inputs through Ajax by POST method to an ASP file to add them back to a database. However, what i noticed is that whenever i send the inputs of the form let's say ("username") through Ajax by the POST method, the result is the input "username" however with no spaces. Why is it that the Ajax POST method ignores the spaces and sends the inputs without the spaces? I tried it with the GET method and found out that GET doesn't ignore the spaces, it worked. But the application that i'm trying to build requires sending bigger data that the GET method can't send. SO therefore i need the POST method but i ran into the problem of Spaces Being Ignored. Please, is there a way to send any string that contains spaces through AJAX POST method and not ignore the spaces in the output??? Thank You David hello, can anyone help me with a javascript-php-ajax problem? I have created a table with checkboxes and whenever an ajax function is called to refresh, the checkboxes that were highlighted and checked get reset, here is my javascript for the check function: $(document).ready(function() { $("#checkall").live('click',function(event){ $('input:checkbox:not(#checkall)').attr('checked',this.checked); //To Highlight if ($(this).attr("checked") == true) { //$(this).parents('table:eq(0)').find('tr:not(#chkrow)').css("background-color","#FF3700"); $("#policy").find('tr:not(#chkrow)').css("background-color","#FC9A01"); } else { //$(this).parents('table:eq(0)').find('tr:not(#chkrow)').css("background-color","#fff"); $("#policy").find('tr:not(#chkrow)').css("background-color","#FFF"); $("#policy").find('tr.alt:not(#chkrow)').css("background-color","#EAF2D3"); } }); $('input:checkbox:not(#checkall)').live('click',function(event) { if($("#checkall").attr('checked') == true && this.checked == false) { $("#checkall").attr('checked',false); $(this).closest('tr').css("background-color","#ffffff"); } if(this.checked == true) { $(this).closest('tr').css("background-color","#FC9A01"); CheckSelectAll(); } if(this.checked == false) { $(this).closest('tr').css("background-color","#ffffff"); $(this).closest('tr.alt').css("background-color","#EAF2D3"); } }); function CheckSelectAll() { var flag = true; $('input:checkbox:not(#checkall)').each(function() { if(this.checked == false) flag = false; }); $("#checkall").attr('checked',flag); } }); Hey, as the subject says... I'm struggling to call other external files from within a file, requested by an Ajax.Request. It's bascically a request to call a file that updates a mysql database, and I want to include my database connection php file so I don't have to keep repeating my connection settings. here is the request: Code: new Ajax.Request('tools/server_reorder_list.php', options); and within that file I'm trying to do something like this: Code: include ("../config/dbconnect.php"); $i=1; foreach($_POST['item_list'] as $key=>$value) { mysql_query("UPDATE `cs_pages` SET `position`='".$i."' WHERE id_page ='".$value."'"); $i++; } I've tried all kinds of ways to include the files, from the above, to typing the entire path. The only way I can get this request to work is by actually typing my connection settings in the requested file. Any help greatly appreciated. Thanks! I am using this code... simplified for example Code: [ <script type="text/javascript"> function loadContent(elementSelector, sourceURL) { $(""+elementSelector+"").load(""+sourceURL+""); } </script> <a onclick="loadContent('#content', 'http://www.website.com/includes/content.php');" <div id="content"></div> Works fine if run on http://www.website.com but not on http://www.website.com/home/sitepage. I have spent a few hours and cannot figure it out. Can anyone? Thanks |