JavaScript - How To Call The Rest Api Via Xmlhttp Request?
Hi,
how to call the rest api via xml http request? I am working in oodle api,i am new for api.how to call the oodle server and retrieve data on xml format?pls help......... send javascript or ajax sample codings............. thanks Similar TutorialsHi, I am trying to make a fuinction that, when called, will return the string that is retrned in text form from my php code. This is what i currently have, but it is just failing when it is run, what am i doing wrong? Code: function shortenUrl(url) { var response; var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "http://10.1.1.10/projects/short/?ext&url=" + encodeURIComponent(url), false); xmlhttp.send(null); xmlhttp.onload = function() { var response = xmlhttp.responseText; return response; } return "Failed!"; } alert(shortenUrl("http://www.google.com.au/")); Thanks Edit: ohh, and this is running chrome, so no standards issues I am trying to use xml http and xml dom with javascript. I currently have this function to load the xml document: Code: function loadXmlDoc(dname) { var xmlDoc; if (window.XMLHttpRequest) { xmlDoc = new window.XMLHttpRequest(); xmlDoc.open("GET",dname,false); xmlDoc.send(""); return xmlDoc.responseXML; } // IE 5 and IE 6 else if (window.ActiveXObject) { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.load(dname); return xmlDoc; } alert("I'm sorry, your browser doesn't support the necessary tools to load this page. Please upgrade your browser or try a different one."); return null; } However, it's not working in any version of IE. I've also tried using Microsoft.XMLHTTP instead of Microsoft.XMLDOM but it's still not working. I'm on a mac and don't have IE so i've been using browsershots.org for testing. So, my url looks like index.php?id=2&name=test&place=14 There is a next link that uses an onClick= to call an ajax function. This ajax function runs this php script (bar_next.php) behind the scenes. I need to put just the id value into the code below. Code: xmlhttp.open("GET","bar_next.php?id=URL VALUES GO HERE",false); Thanks. Alright, so I've been writing a plain javascript file, which is called by HTML later to grab information from a certain page and then parse through that information. This is being done as a Windows Gadget, so the "browser" is IE. I have two main problems with this: One is caching. I can't get not caching to work at all. I've tried headers and I've tried putting something random at the end of the URL. The randomness at the end of the URL works when done from an HTML file embedded with Javascript but will not work from a pure Javascript file. My other, potentially bigger, problem is that the xmlhttp object does not seem to ever want to open again. I'm pretty sure what's happening is it doesn't get back into ready state 4. That is, unless I run an html file that accesses the same url. Then, suddenly, the gadget runs its update function and it actually decides to work. The gadget still runs the update function otherwise but it doesn't actually do anything, which is I believe caused by it never getting back to ready state 4 on its own. I appreciate any help on this, and if I didn't explain anything clearly I'm more than happy to clarify. Cheers. I am trying to figure out that if the function "xmlhttp.onreadystatechange=function()" returns true the whole function "function checkUser(str)" should return true as well....so not sure how to do it. i have banged my head since long so please advise! Here is the code below: -------------------------------------------------------- function checkUser(str) { var sp = document.getElementById("msgs"); if (str=="") { document.getElementById("msgs").innerHTML="Username cannot be empty."; return false; } if (str.length <= 6) { document.getElementById("msgs").innerHTML="Username cannot be less than 6 characters and must not start with a number or a special value"; return false; } if (window.XMLHttpRequest) { //code for IE7+, firefox, chrome, opera, safari xmlhttp=new XMLHttpRequest(); } else { //code for old IE xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { if (xmlhttp.responseText === 'FOUND') { sp.style.color = "red"; sp.innerHTML = "[ERROR]: The username \"" + str + "\" already exist. Please try a different name."; return false; } else if (xmlhttp.responseText === 'NOT FOUND') { sp.style.color = "blue"; sp.innerHTML = "Username: VALID"; return true; } } } xmlhttp.open("GET", "checkUser.php?q="+str,true); xmlhttp.send(); } Hi Guys I am using a CMS where the blogging platform isn't the greatest. Basically I am wanting to give the first post preview different styling to the rest of the post previews on the page. Here is an example of what I am trying to achieve: http://www.stylingyou.com.au/ You can see the first post preview has a bg color and border etc. So here is the code my CMS outputs for the blog previews Code: <div id="catblogoutput"> <div class="blog-post"> 1st blog preview here </div> <div class="blog-post"> 2nd blog preview here </div> <div class="blog-post"> 3rd blog preview here </div> </div> As you can see each div is named the same and I can not change this. So I am thinking the JS would say something like: if it is the first div blog-post then use this css class Obviously I am no JS expert, so let me know if this is possible. Thanks I am wanting to allow a user to update their twitter status from my website. I was planning on using Twitter's @anywhere feature, but this was not a very friendly solution: Take over 3 seconds to load Makes 14 requests Calls jQuery twice Then I found the Twitter REST API: https://dev.twitter.com/docs/api Using OAuth, I want the user to be able to login, and then update their status using that API. I've been trying to find tutorials on this, but I haven't found any that use the REST API to update the Twitter Status. Does anyone have code for/know of a tutorial for what I'm looking for? hello.... i am needing help writing a function that when onclick it shows a specific element id and hides all the rest of the the ids i have php code that shows a list of colored boxes and when you click one it changes the color of a div... this works fine as i have used a changecss function... i have these colors in a database with their values and specific color names... what i am trying to do is when a color is clicked it will change the div and also print the color name.... i have made a php loop to print all the color names and i have the display as none... how can i add to the onclick function that changes the color to also put the display of the certain color name to "block" and then if you select another color it hides that one and shows the new color... any help is appreciated! i'm sorry if this is confusing Hi, I am hoping I just need to be pointed in the right direction with this. I have Page1. When Page1 body onloads it uses Ajax to call PartA Within PartA I have a message board so members can write messages which will be sent to my database in PartA[1] and immediately posted for view on to PartA[2]. As I want to have my request to the server updating regularly I want to have PartA[2] on a timed loop to refresh - I do not need the content of PartA[1] to refresh. So the order of events would look like this: Page1 | onload call | v PartA / \ V V PartA[1] PartA[2] (loads once) (constantly refreshes) What I am not sure about is that I have <body> and <head> attributes in Page1 only. I have already used my body onload to call PartA (and can't use it to call PartA[2] before PartA has loaded anyway). I do not want the user to have to click a button or do anything to call up PartA[2]. So my question is how would I get PartA[2] to automatically load within PartA? I hope I have made this clear, but if I haven't let me know and I will try again. OK, a friend and I have been working on implementing the javascript slider you see in the header of my website http://www.billboardfamily.com (hover over the facebook icon under the search area). For some reason, this is causing a lot of the other items on the site to stop functioning all together. Can anyone help me figure out how to fix this? NOTE: Running Wordpress Here are some of the problems: 1) http://billboardfamily.com/videos/ The thumbnail videos do not work when you click them 2) http://billboardfamily.com/the-process/ All 4 slides are on the page, but the slider is not working at all. 3) http://billboardfamily.com/contact-us/ The contact forms I have running are not working correctly, and the styling is no longer correct. Is there a way of doing this with javascript? I have a homepage, that has to go to a certain directory, find the newer TXT file, get the first paragraph, get it formated with H1 tag, then read the rest format it with a P tag. So everytime a new TXT file is created in that directory the homepage (HTML/index.html) change. Thank in advance Miguel Sanchez Is there a way of doing this with java script? I have a homepage, that has to go to a certain directory, find the newer TXT file, get the first paragraph, get it formated with H1 tag, then read the rest format it with a P tag. So everytime a new TXT file is created in that directory the homepage (HTML/index.html) change. Thank in advance Miguel Sanchez I'm not a programmer, just a lowly photographer that manages some websites. A company that provides Print-on-Demand services for me has some code that works in most browsers, but not in IE (at least older versions). It has to do with an onClick routine, and after some google searchs, I saw that similar issues have been common for years. Yet I didn't really understand the solutions. I put up a test page with the relevant code snippet. In Chrome, if one clicks on the image, the sales page comes up. In IE, nothing happens. I gathered that any error will bog down IE. If someone recognizes the problem or knows of a solution, I would be most grateful. The example page is here. The code snippet is below. Thanks in advance for anyone taking the time to look. <img src='http://images.fineartamerica.com/images-medium-large-5/autumn-peak-at-oxbow-bend-greg-norrell.jpg' style='position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; border: none; z-index: 0;''> <div onTouchEnd='javascript: if(tap){window.location="http://photoartresource.com/featured/autumn-peak-at-oxbow-bend-greg-norrell.html";}' onClick='javascript: window.location="http://photoartresource.com/featured/autumn-peak-at-oxbow-bend-greg-norrell.html";' style='position: absolute; width: 100%; height: 100%; background-color: transparent; z-index: 1;'> </div> Can someone modify the code below to save name & email to a file named logfile.dat please? Code: <html> <HEAD> <SCRIPT language="JavaScript"> function WriteFile(name, email) { var fso = new ActiveXObject("Scripting.FileSystemObject"); var fh = fso.CreateTextFile("D:\\logfile.dat", true); fh.WriteLine(name); fh.WriteLine(email); fh.Close(); } function sendtopage(whatpage) { alert(whatpage) window.location.href =whatpage; return true; } redirectTime = "3000"; redirectURL = "http://www.cnn.com"; function timedRedirect() { alert('Thank you'); setTimeout("location.href = redirectURL;",redirectTime); } function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } } function setCookie(c_name,value,exdays) { var exdate=new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie=c_name + "=" + c_value; } function checkEmailCookie() { var email=getCookie("email"); if (email!=null && email!="") { alert("Email: " + email); } } function checkNameCookie() { var name=getCookie("name"); if (name!=null && name!="") { alert("Name: " + name); } } </SCRIPT> <style type="text/css"> .Class01 { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; font-size: 24px; font-weight: bold; } .Class02 { font-size: 36px; font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; } .Class013 { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; } .Class01 .Class013 .Class01 { font-weight: bold; } .Classzz { font-family: "Lucida Console", Monaco, monospace; } .Classxx { font-weight: bold; font-size: 24px; } .Classzz { font-family: "Lucida Console", Monaco, monospace; } .style1 { text-align: center; } </style> </HEAD> <body gcolor="#FFFFFF" background="../MCM-background.jpg"> <center> <p class="style1"><img src="../mcm_header2.gif" alt="Header" width="790" height="199"></p> </center> <p></p> <form name="fm" action="http://www.meadecountymessenger.com"> <div align="center"> <p> </p> <p><span class="Class01"><span class="Class02">Please enter the following.</span></span></p> <p> </p> <p><span class="Class01">Your Name: </span> <input name="name" type="text" size="60" /> </p> <p><span class="Classzz"><br /> <span class="Classxx">Your eMail:</span></span><span class="Class01"> </span> <input name="email" type="text" size="60" /> <script type="text/javascript"> setCookie("email",document.fm.email.value,365); setCookie("name",document.fm.name.value,365); </SCRIPT> </p> <p> <input name="" type="submit" class="Class01" OnClick="alert('Thank You !');" value="Submit"/> </p> </div> </form> </body> </html> Hi. I need to load an iFrame, take the contents from it, and pass it to a file (getjson.php), which will pass data back to the file, and then display it in a div. I've tried so many different ways. The main file is on mydomain.com, and the file I'm accessing is on mydomain.com:2086, just so you know. i m trying to implement captcha in my site.i m using recaptcha. To check the captcha i need to request url like: http://www.google.com/recaptcha/api/verify?privatekey="key"&remoteip="ip"&challenge="chal"&response="res" and then i need to check response from url if it is true or false i dont know how to request response from url help plz Hey all, Was just wondering if anyone knew what type of content slider is this http://www.builtbybuffalo.com/ and were could i get one? Thanks in advance Kyle HI there.. Can you please give me code in JavaScript to create a student request form for book request from issue section of college Library.. Please help with code... Thanx in advance... Regards, hi, I had a doubt... here is a simple ajax program to return the length of the string entered in the input html: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type='text/javascript' src="grade.js" > </script> <title>Untitled Document</title> </head> <body> <form action="fallbackpage.php" method="post"> <p>Welcome, student. Please enter your essay he </p> <p> <textarea name="essay" id="essay"> </textarea> </p> <p> <input type="submit" name="submit" value="Submit" onclick=" grade(this.form.essay.value);" /> </p> </form> </body> </html> Java script Code: // JavaScript Document function grade(essay) { // Mozilla version if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } // IE version else if (window.ActiveXObject) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } essay=encodeURIComponent(essay); xhr.open("POST","grade.php"); xhr.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); xhr.send(essay); xhr.onreadystatechange=function() { if (xhr.readyState==4) { grade = xhr.responseText; alert(grade); } } } php: PHP Code: <?php function grade_essay($essay) { return strlen($essay); } $essay = urldecode(implode(file('php://input'))); $grade = grade_essay($essay); echo $grade; ?> I just use an alert box to alert the length. The script works properly ONLY when the AJAX request is able to outrace the submit request.... which doesnt happen. I have included the action="" part as a fallback option incase JS is disabled What am i doing wrong here? I am learning JS now in the free time... Also i did notice this... when i change the submit button in html to the following code i get 2 alert box..1st one's undefined(i know why) but second one's i will get proper answer Quote: <input type="submit" name="submit" value="Submit" onclick="alert(grade(this.form.essay.value));" /> PS: This is a tutorial here http://www.webmonkey.com/2010/02/aja...ners/#more-775 |