Search Results

Search found 260 results on 11 pages for 'readystate'.

Page 8/11 | < Previous Page | 4 5 6 7 8 9 10 11  | Next Page >

  • function returns after an XMLHttpRequest

    - by ashays
    Alright, I know questions like this have probably been asked dozens of times, but I can't seem to find a working solution for my project. Recently, while using jQuery for a lot of AJAX calls, I've found myself in a form of callback hell. Whether or not jQuery is too powerful for this project is beyond the scope of this question. So basically here's some code that shows what's going on: function check_form(table) { var file = "/models/"+table+".json"; var errs = {}; var xhr = $.getJSON(file, function(json) { for (key in json) { var k = key; var r = json[k]; $.extend(errs, check_item("#"+k,r)); } }); return errs; } And... as you can probably guess, I get an empty object returned. My original idea was to use some sort of onReadyStateChange idea that would return whenever the readyState had finally hit 4. This causes my application to hang indefinitely, though. I need these errors to decide whether or not the form is allowed to submit or not (as well as to tell the user where the errors are in the application. Any ideas? Edit. It's not the prettiest solution, but I've managed to get it to work. Basically, check_form has the json passed to it from another function, instead of loading it. I was already loading it there, too, so it's probably best that I don't continue to load the same file over and over again anyways. I was just worried about overloading memory. These files aren't absolutely huge, though, so I guess it's probably okay.

    Read the article

  • XMLHttpRequest leak

    - by Raja
    Hi everyone, Below is my javascript code snippet. Its not running as expected, please help me with this. <script type="text/javascript"> function getCurrentLocation() { console.log("inside location"); navigator.geolocation.getCurrentPosition(function(position) { insert_coord(new google.maps.LatLng(position.coords.latitude,position.coords.longitude)); }); } function insert_coord(loc) { var request = new XMLHttpRequest(); request.open("POST","start.php",true); request.onreadystatechange = function() { callback(request); }; request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); request.send("lat=" + encodeURIComponent(loc.lat()) + "&lng=" + encodeURIComponent(loc.lng())); return request; } function callback(req) { console.log("inside callback"); if(req.readyState == 4) if(req.status == 200) { document.getElementById("scratch").innerHTML = "callback success"; //window.setTimeout("getCurrentLocation()",5000); setTimeout(getCurrentLocation,5000); } } getCurrentLocation(); //called on body load </script> What i'm trying to achieve is to send my current location to the php page every 5 seconds or so. i can see few of the coordinates in my database but after sometime it gets weird. Firebug show very weird logs like simultaneous POST's at irregular intervals. Here's the firebug screenshot: IS there a leak in the program. please help. EDIT: The expected outcome in the firebug console should be like this :- inside location POST .... inside callback /* 5 secs later */ inside location POST ... inside callback /* keep repeating */

    Read the article

  • Chrome extension sendRequest from async callback not working?

    - by Eugene
    Can't figure out what's wrong. onRequest not triggered on call from async callback method, the same request from content script works. The sample code below. background.js ============= ... makeAsyncRequest(); ... chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { switch (request.id) { case "from_content_script": // This works console.log("from_content_script"); sendResponse({}); // clean up break; case "from_async": // Not working! console.log("from_async"); sendResponse({}); // clean up break; } }); methods.js ========== makeAsyncRequest = function() { ... var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { ... // It works console.log("makeAsyncRequest callback"); chrome.extension.sendRequest({id: "from_async"}, function(response) { }); } } ... }; UPDATE: manifest configuration file. Don't no what's wrong here. { "name": "TestExt", "version": "0.0.1", "icons": { "48": "img/icon-48-green.gif" }, "description": "write it later", "background_page": "background.html", "options_page": "options.html", "browser_action": { "default_title": "TestExt", "default_icon": "img/icon-48-green.gif" }, "permissions": [ "tabs", "http://*/*", "https://*/*", "file://*/*", "webNavigation" ] }

    Read the article

  • Excel 2010 VBA code is stuck when UserForm is shown

    - by Denis
    I've created a UserForm as a progress indicator while a web query (using InternetExplorer object) runs in the background. The code gets triggered as shown below. The progress indicator form is called 'Progerss'. Private Sub Worksheet_Change(ByVal Target As Range) If Target.Row = Range("B2").Row And Target.Column = Range("B2").Column Then Progress.Show vbModeless Range("A4:A65535").ClearContents GetWebData (Range("B2").Value) Progress.Hide End If End Sub What I see with this code is that the progress indicator form pops up when cell B2 changes. I also see that the range of cells in column A gets cleared which tells me that the vbModeless is doing what I want. But then, somewhere within the GetWebData() procedure, things get hung up. As soon as I manually destroy the progress indicator form, the GetWebData() routine finishes and I see the correct results. But if I leave the progress indicator visible, things just get stuck indefinitely. The code below shows what GetWebData() is doing. Private Sub GetWebData(ByVal Symbol As String) Dim IE As New InternetExplorer 'IE.Visible = True IE.navigate MyURL Do DoEvents Loop Until IE.readyState = READYSTATE_COMPLETE Dim Doc As HTMLDocument Set Doc = IE.document Dim Rows As IHTMLElementCollection Set Rows = Doc.getElementsByClassName("financialTable").Item(0).all.tags("tr") Dim r As Long r = 0 For Each Row In Rows Sheet1.Range("A4").Offset(r, 0).Value = Row.Children.Item(0).innerText r = r + 1 Next End Sub Any thoughts?

    Read the article

  • Read a text file

    - by Cyprus106
    I have looked everywhere and surprisingly can't find a good solution to this! I've got the following code that is supposed to read a text file and display it's contents. But it's not reading, for some reason. Am I doing something wrong? FTR, I can't use PHP for this. It's gotta be Javascript. var txtFile = new XMLHttpRequest(); txtFile.open("GET", "http://www.mysite.com/todaysTrivia.txt", true); txtFile.send(null); txtFile.onreadystatechange = function() { if (txtFile.readyState == 4) { // Makes sure the document is ready to parse. alert(txtFile.responseText+" - "+txtFile.status); //if (txtFile.status === 200) { // Makes sure it's found the file. var doc = document.getElementById("Trivia-Widget"); if (doc) { doc.innerHTML = txtFile.responseText ; } //} } txtFile.send(null); } Any good ideas what I'm doing wrong? It just keeps givimg me a zero status. EDIT: I guess it would be a good idea to explain why I need this code. It's basically a widget that other folks can put on their own websites that grabs a line of text from my website and displays it on theirs. The problem is that it really can't be server-side since I've got zero control over everyone else's sites that use this.

    Read the article

  • use of ajax in django problem with the code

    - by tazim
    I am new to ajax and using Django for web development. Now My Template contains : sample.html <html> <body> <script language="javascript" type="text/javascript"> //Browser Support Code function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = 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 ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ document.myForm.time.value = ajaxRequest.responseText; } } ajaxRequest.open("GET", "/showtime/", true); ajaxRequest.send(null); } </script> <form name='myForm'> Name: <input type='text' onBlur="ajaxFunction();" name='username' /> <br /> Time: <input type='text' name='time' /> </form> </body> </html> In views.py my function is : def showtime(request): string = "Ajax Application" data = {"string" : string} pprint (data) return render_to_response("sample.html",data) Now, The output is not as expected . The template does not receives the response sent by the server What is wrong with the code ?

    Read the article

  • Javascript Object Properties go to undefined after ajax request returns

    - by adasdas
    if you have an object and set a property for it, you can access that property in a function called on that object. but if you call a function and do an ajax request such that a different function is called from onreadystatechange, that secondary response function does not have access to the property. Thats a little confusing so see what I mean here. The property this.name is the one that changes. //from W3Schools website function getXHR(){if (window.XMLHttpRequest){return new XMLHttpRequest();}if (window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP");}return null;} function TestObject() { this.name = ""; //public var xhr = null; //private var response = function() //private { if(xhr.readyState > 3) { alert("B: my name is " + this.name); } } this.send = function() //public { alert("A: my name is " + this.name); if(xhr === null) { xhr = getXHR(); } var url = "http://google.com"; xhr.onreadystatechange = response; xhr.open("GET", url, true); xhr.send(null); } } var o = new TestObject(); o.name = "Ice Cube"; o.send(); Results are: A: my name is IceCube B: my name is undefined If response is public this happens as well. If xhr is public this also happens. Something occurs so that the response function called doesnt have access to the same parameters.

    Read the article

  • Ajax div can't access address bar variable

    - by Elaine Adams
    Can someone please advise me on how my Ajax div can get an address bar variable. The usual way just doesn't work. My address bar currently looks like this: http://localhost/social3/browse/?locationName=Cambridge Usually, I would use a little php and do this: $searchResult = $_POST['locationName']; echo $searchResult; But because I'm in an Ajax div, I can't seem to get to the variable. Do I need to add some JavaScript wizardry to my Ajax coding? (I have little knowledge of this) My Ajax: <script> window.onload = function () { var everyone = document.getElementById('everyone'), searching = document.getElementById('searching'), searchingSubmit = document.getElementById('searchingSubmit'); everyone.onclick = function() { loadXMLDoc('indexEveryone'); everyone.className = 'filterOptionActive'; searching.className = 'filterOption'; } searching.onclick = function() { loadXMLDoc('indexSearching'); searching.className = 'filterOptionActive'; everyone.className = 'filterOption'; } searchingSubmit.onclick = function() { loadXMLDoc('indexSearchingSubmit'); } function loadXMLDoc(pageName) { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("leftCont").innerHTML=xmlhttp.responseText; } } function get_query(){ var url = location.href; var qs = url.substring(url.indexOf('?') + 1).split('&'); for(var i = 0, result = {}; i < qs.length; i++){ qs[i] = qs[i].split('='); result[qs[i][0]] = decodeURIComponent(qs[i][1]); } return result; } xmlhttp.open("GET","../browse/" + pageName + ".php?user=" + get_query()['user'],true); xmlhttp.send(); } } </script> <!-- ends ajax script -->

    Read the article

  • XMLHttpRequest POST Data Size

    - by usurper
    Hi, Is there a size limit to a XHR POST request? I am using the POST method for saving textdata into MySQL using PHP script and the data is cut off. Firebug sends me the following message: ... Firebug request size limit has been reached by Firebug. ... This is my code for sending the data: function makeXHR(recordData) { xmlhttp = createXHR(); var body = "q=" + encodeURIComponent(recordData); xmlhttp.open("POST", "insertRowData.php", true); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", body.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { //alert(xmlhttp.responseText); alert("Records were saved successfully!"); } } xmlhttp.send(body); } The only solution I can think of is splitting the data and making a queue of XHR requests but I don't like it. Is there another way?

    Read the article

  • Two AJAX asynchronus GET call: Only one get the xml file

    - by Woho87
    Hi! I have two AJAX GET calls that are set to asynchcronus = true; I want to obtain two XML files on my server. The two AJAX calls and rendering are defined in function foo & koo. And are called simultaneously. function foo(){ var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ var xmlDoc = xmlhttp.responseXML; //Do something } } xmlhttp.open('get', 'url', true); xmlhttp.send(); } function koo(){ //Almost the same as function foo } foo(); koo(); I've noticed that inside the if statement in the first function call(foo), the code their will never compile. While in the second function call(koo). The code inside the if statement can be compiled. If I set both asynchronus to false, then there is no problem at all. If I remove the second function call(koo) from the code, than the code inside the if statement can be compiled. What can I do to have both asynchronus AJAX calls?

    Read the article

  • Problem with making a simple JS XmlHttpRequest call

    - by recipriversexclusion
    I have to create a very simple client that makes GET and POST calls to our server and parses the returned XML. I am writing this in JavaScript, problem is I don't know how to program in JS (started to look into this just this morning)! As n initial test, I am trying to ping to the Twitter API, here's the function that gets called when user enters the URL http://api.twitter.com/1/users/lookup.xml and hits the submit button: function doRequest() { var req_url, req_type, body; req_url = document.getElementById('server_url').value; req_type = document.getElementById('request_type').value; alert("Connecting to url: " + req_url + " with HTTP method: " + req_type); req = new XMLHttpRequest(); req.open(req_type, req_url, false, "username", "passwd");// synchronous conn req.onreadystatechange=function() { if (req.readyState == 4) { alert(req.status); } } req.send(null); } When I run this on FF, I get a Access to restricted URI denied" code: "1012 error on Firebug. Stuff I googled suggested that this was a FF-specific problem so I switched to Chrome. Over there, the second alert comes up, but displays 0 as HTTP status code, which I found weird. Can anyone spot what the problem is? People say this stuff is easier to use with JQuery but learning that on top of JS syntax is a bit too much now.

    Read the article

  • innerhtml not working on blogger

    - by HAnlin Cal
    I'm working on a simple vote system. It works fine when the two files are together(locally). However, when I publish it on blogger, it is unable to output the results. (on click the vote gets registered on the webhost, but the results just don't show!) heres my code: <script type="text/javascript"> function getVote(int) { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("poll").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","http://pacontest.eu.pn/poll_vote.php?vote="+int,true); xmlhttp.send(); } </script> <div id="poll"> <h3>Do you like this?</h3> <form> Yes: <input type="radio" name="vote" value="0" onclick="getVote(this.value)" /> No: <input type="radio" name="vote" value="1" onclick="getVote(this.value)" /> </form> </div>

    Read the article

  • Javascript object binding problem inside of function prototype definitions

    - by Arion
    Hi all, I am trying to figure out the right place to bind a function prototype to be called later. The full code of the example can be found here: http://www.iprosites.com/jso/ My javascript example is very basic: function Obj(width, height){ this.width = width; this.height = height; } Obj.prototype.test = function(){ var xhr=init(); xhr.open('GET', '?ajax=test', true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); xhr.onreadystatechange = function() { if (xhr.responseText == '403') { window.location.reload(false); } if (xhr.readyState == 4 && xhr.status == 200) { this.response = parseResponse(xhr.responseText); document.getElementById('resp').innerHTML = this.response.return_value; this.doAnotherAction(); } }; xhr.send(); } Obj.prototype.doAnotherAction = function(){ alert('Another Action Done'); } var myo = new Obj(4, 6); If you try to run myo.test() in Firebug, you will get the "this.doAnotherAction is not a function" response. The 2 support functions init() and parseResponse() can be found in the test.js link if you wish to view them, but should not be too relevant to this problem. I've affirmed that this.doAnotherAction() thinks "this" is the XMLHttpResponse object as expected from an instanceof test. Can anyone help with some insight on direction with binding? Everything I've tried seems not to work! I do use Mootools, although the library is not present in this example. Thanks in advance, Arion

    Read the article

  • Access is denied. Javascript error on request to secured page

    - by ihorko
    On SomePage.aspx page by javascript (XMLHttpRequest) I call SecuredPage.aspx used next code: var httpRequest = GetXmlHttp(); var url = "https://myhost.com/SecuredPage.aspx"; var params = "param1=" + document.getElementById('param1').value + "&param2=" + document.getElementById('param2').value; httpRequest.open("POST", url, true); httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); httpRequest.onreadystatechange = function() { //Call a function when the state changes. if (httpRequest.readyState == 4 && httpRequest.status == 200) { alert(httpRequest.responseText); } } httpRequest.send(params); // HERE ACCESS IS DENIED //--------------------------------------------- function GetXmlHttp() { var xmlhttp = false; if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); } else if (window.ActiveXObject) // code for IE { try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } } return xmlhttp; } It throws Access is denied error. if send to http (http://myhost.com/SecuredPage.aspx), it works fine. How is it possible to resolve that problem. Thanks!

    Read the article

  • Is this state-of-the-art Ajax/jQuery, or should I do it differently?

    - by AP257
    Hi everyone: I'm using Ajax and jQuery to do some cool client-side stuff. Basically, if the user chooses a subject from a from a drop-down list, I want to auto-populate the page with a set of book details. However, I've built the Ajax from Google results and bits of string. I don't know if what I've done is up-to-date, or whether there are now much neater ways of doing it! Here's what I have: can it be improved? $("#subjectlist").change(function() { if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { var book_details = eval(xmlhttp.responseText); alert(book_details[0]["url"]); // To be added: extra code to populate HTML results. document.getElementById("book_results").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","/subject_json/?id=" + $("#subjectlist").val(),true); xmlhttp.send(); }); Thanks for any advice!

    Read the article

  • Receiving AJAX HTTP Response Code as 0

    - by shyam
    I have a pretty simple AJAX and PHP code. While calling the PHP through the AJAX it receives the response code as 0. The PHP code is successfully run, but I can't get the response. What does this status '0' denote and how can I solve this? function confirmUser(id) { xmlhttp=GetXmlHttpObject(); regid = id; if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="confirm.php"; url=url+"?id="+id; url=url+"&a=confirm"; xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { $("#txtHint" + regid).text("Awaiting confirmation"); } else { alert (xmlhttp.status); //this shows '0' } }; xmlhttp.open("GET",url,true); xmlhttp.send(null); } Well, this is the javascript I used. Pardon me if I should've added anything more than this. Also tell me what I missed. I appreciate your help

    Read the article

  • Chrome.tabs.getSelected() doesn't work. What am I doing wrong ?

    - by warv3n
    Hi there ! I'm building my first GC extension, and I am having a problem using this function. I would like to get the url of the current tab, and to do so (after some google research, of course), I use the chrome.tabs.getSelected() function. Here it is in my code : ... socket.onopen = function(msg){ log("Welcome - status " + this.readyState); chrome.tabs.getSelected(null, function(tab){ sendUrl(tab.url); }); }; function sendUrl(tabUrl) { socket.send("#URL#"+ tabUrl); } The socket.open is a listener for the Websocket API I use in my extension. The log function print the status of the socket (1, which means it's OPEN or connected and ready to communicate, according to the Websocket API), but the chrome.tabs.getSelected() function do not seems to work, as the server do not receive anything (the socket is not the problem here, I tried to send a test message with socket.send() instead of chrome.tabs.getSelected() and the server received it). I put the permissions: ["tabs"] into the manifest.json so I can use this function. So I don't know what I am doing wrong here ? I also tried to put chrome.tab.getSelected() elsewhere in the code, but it is still not working. Any help is welcome :)

    Read the article

  • Ajax return string links not working

    - by Andreas Lympouras
    I have this ajax function: function getSearchResults(e) { var searchString = e.value; /*var x = e.keyCode; var searchString = String.fromCharCode(x);*/ if (searchString == "") { document.getElementById("results").innerHTML = ""; return; } var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("results").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", "<%=Page.ResolveUrl("~/template/searchHelper.aspx?searchString=")%>"+searchString, true); xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"); //solve any AJAX caching problem(not refreshing) xmlhttp.send(); } and here is when I call it: <input class="text-input" value="SEARCH" id="searchbox" onkeyup="javascript:getSearchResults(this);" maxlength="50" runat="server" /> and all my links in the searchHelper.aspx file(which retruns them as a string) are like this: <a class="item" href='../src/actors.aspx?id=77&name=dasdassss&type=a' > <span class="item">dasdassss</span></a> When I click this link I want my website to go to ../src/actors.aspx?id=77&name=dasdassss&type=a but nothing happens. When I hover over the link, it also shows me where the link is about to redirect! any help?

    Read the article

  • Script (AJAX or JS) does not work properly in IE8

    - by Uno Mein Ame
    I have a js/ajax script at http://worldcitiesdatabase.info/test1/ I just received a complaint that it does not work properly in IE8. Onchange seems to work, but then the next menu is not populated. Can you please help me figure it out? Thanks Not sure what the problematic part of the code is. Here is my guess: if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } newList=""; xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { newList = xmlhttp.responseText; m1.innerHTML=newList; m1.disabled=false; } if (menuname=="showCountry") { var c1=document.getElementById('showRegion'); if (c1.options.length==2) { if (c1.options[0].value=='NONE') { c1.remove(0); c1.value='0'; reloadmenu(c1); } } } } xmlhttp.open("GET",newFile+".php?q="+menuvalue,true); xmlhttp.send();

    Read the article

  • JavaScript: When does JavaScript evaluate a function, onload or when the function is called?

    - by Benj
    When does JavaScript evaluate a function? Is it on page load or when the function is called? The reason why I ask is because I have the following code: function scriptLoaded() { // one of our scripts finished loading, detect which scripts are available: var jQuery = window.jQuery; var maps = window.google && google.maps; if (maps && !requiresGmaps.called) { requiresGmaps.called = true; requiresGmaps(); } if (jQuery && !requiresJQuery.called) { requiresJQuery.called = true; requiresJQuery(); } if (maps && jQuery && !requiresBothJQueryGmaps.called) { requiresBothJQueryGmaps.called = true; requiresBothJQueryGmaps(); } } // asynch download of script function addScript(url) { var script = document.createElement('script'); script.src = url; // older IE... script.onreadystatechange=function () { if (this.readyState == 'complete') scriptLoaded.call(this); } script.onload=scriptLoaded; document.getElementsByTagName('head')[0].appendChild(script); } addScript('http://google.com/gmaps.js'); addScript('http://jquery.com/jquery.js'); // define some function dependecies function requiresJQuery() { // create JQuery objects } function requiresGmaps() { // create Google Maps object, etc } function requiresBothJQueryGmaps() { ... } What I want to do is perform asynchronous download of my JavaScript and start at the earliest possible time to begin executing those scripts but my code has dependencies on when the scripted have been obviously downloaded and loaded. When I try the code above, it appears that my browser is still attempting to evaluate code within my require* functions even before those functions have been called. Is this correct? Or am I misunderstanding what's wrong with my code?

    Read the article

  • Clarification of a some code

    - by Legend
    I have come across a website that appears to use Ajax but does not include any js file except one file called ajax.js which has the following: function run(c, f, b, a, d) { var e = null; if (b && f) { document.getElementById(b).innerHTML = f } if (window.XMLHttpRequest) { e = new XMLHttpRequest() } else { if (window.ActiveXObject) { e = new ActiveXObject(Microsoft.XMLHTTP) } } e.onreadystatechange = function () { if (e.readyState == 4) { if (e.status == 200 || e.statusText == "OK") { if (b) { document.getElementById(b).innerHTML = e.responseText } if (a) { setTimeout(a, 0) } } else { console.log("AJAX Error: " + e.status + " | " + e.statusText); if (b && d != 1) { document.getElementById(b).innerHTML = "AJAX Error. Please try refreshing." } } } }; e.open("GET", c, true); e.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); e.send(null) } Like you might have guessed, the way it issues queries inside the page with queries like this: run('page.php',loadingText,'ajax-test', 'LoadSamples()'); I must admit that this is the first time I've seen a page from which I could not figure how things are being done. I have a few questions: Is this Server-Side Ajax or something similar? If not, can someone clarify what exactly is this? Why does one use this? Is it for hiding the design details? (which are otherwise revealed in plain text by javascript) How difficult would it be to convert my existing application into this design pattern? (maybe a subjective question but any short suggestion will do) Any suggestions?

    Read the article

  • jquery ajax problem in chrome

    - by spaceman
    i have the following jquery code running on my page just fine in FF and IE, but chrome seems to be freaking out.. in FF and IE the call is made and the result is appended to the div. in chrome, it calls ajaxfailed on failure. the XMLHttpRequest passed to the AjaxFailed function has a status code of "200" and the statusText is "ok". the readystate is 4 and the responseText is set to the data i wish to append to the div.. basically from what i can see its calling the failure method but it isn't failing.. i have tried with both get and post requests and it always breaks in chrome. function getBranchDetails(contactID, branchID) { $.ajax({ type: "GET", url: urlToRequestTo, data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: branchDetailsSuccess, error: AjaxFailed }); } function branchDetailsSuccess(result) { $("#divBranchControl").empty(); $("#divBranchControl").append(" " + result); $("#branchDiv").tabs(); } function AjaxFailed(result) { alert("FAILED : " + result.status + ' ' + result.statusText); }

    Read the article

  • Sending an AJAX Request - Can't get to work

    - by user357944
    I'm trying to make an AJAX GET request, but I simply cannot get it to work. I want to retrieve the HTML source of example.com. I've previously used JQuery to send AJAX requests, but I use JQuery only for its AJAX capabilities so it's a waste to include the 30KB file for one task. What is it that I'm doing wrong? <script type="text/javascript"> var XMLHttpArray = [ function() {return new XMLHttpRequest()}, function() {return new ActiveXObject("Msxml2.XMLHTTP")}, function() {return new ActiveXObject("Msxml2.XMLHTTP")}, function() {return new ActiveXObject("Microsoft.XMLHTTP")} ]; function createXMLHTTPObject(){ var xmlhttp = false; for(var i=0; i<XMLHttpArray.length; i++){ try{ xmlhttp = XMLHttpArray[i](); }catch(e){ continue; } break; } return xmlhttp; } function AjaxRequest(url,method){ var req = createXMLHTTPObject(); req.onreadystatechange= function(){ if(req.readyState != 4) return; if(req.status != 200) return; return req.responseText; } req.open(method,url,true); req.send(null); } function MakeRequst(){ var result=AjaxRequest("http://example.com","get"); alert(result); } </script>

    Read the article

  • Download Canvas Image Png Chome/Safari

    - by user2639176
    Works in Firefox, and won't work in Safari, or Chrome. function loadimage() { var canvas = document.getElementById("canvas"); if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); xmlhttp2=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { rasterizeHTML.drawHTML(xmlhttp.responseText, canvas); var t=setTimeout(function(){copy()},3000) } } xmlhttp.open("GET","/sm/<?=$sm[0];?>",true); xmlhttp.send(); } function copy() { var canvas = document.getElementById("canvas"); var img = canvas.toDataURL("image/png"); document.getElementById('dl').href = img; document.getElementById('dl').innerHTML = "Download"; } Now I didn't write this, so I don't know too much javascript. But the script works in Firefox. In Chrome, getting: Uncaught Security Error: An attempt was made to break through the security policy of the user-agent. For toDataURL("image/png")

    Read the article

  • [JavaScript] Function making a slight miscalculation.

    - by Stanni
    Hi, To begin with, I have a database that holds map data for a game I am creating. A script on my page uses JSON to retrieve a certain amount of that data from the database and store it in an array. When the data is retrieved it goes through a function that finds out how many individual tiles are used in that particular area. Here is the code: var xmlhttp = new XMLHttpRequest; xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4){ var map = JSON.parse(xmlhttp.responseText); var mapTiles = new Array; for(var count = 0; count < map.length; count ++){ if(map[count]){ if(map[count]['tile'] in mapTiles == false){ mapTiles.push(map[count]['tile']); } } } alert(mapTiles); } } For each time the script finds a tile number that isn't already in the mapTiles array it adds it to it. Currently, the script is fetching 1024 records that all but one contain the tile value of '1' the other of which contains the tile value of '2'. This means that when I alert the mapTiles array it should display "1, 2" but instead it displays "1, 1, 2". So there is a slight error in the script but I cannot find it.

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11  | Next Page >