Search Results

Search found 535 results on 22 pages for 'xmlhttprequest'.

Page 11/22 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • How to show errors using JSON when an update fails in Rails 2.3.5 with jQuery

    - by Fortuity
    I've got in-place editing on a page in my app (using Rails 2.3.5 and jQuery). I want to know how to display an error on the page when the update fails. I'm using ajax (an XMLHttpRequest) to save an update to a Comment object. The controller has an update method like this: def update @comment = Comment.find(params[:id]) respond_to do |format| # if @comment.update_attributes!(params[:comment]) if false #deliberately forcing a fail here to see what happens format.json { render :nothing => true } else format.json { render :json => @comment.errors, :status => :unprocessable_entity } end end end In Firebug, I can see the server returns a "422" (an appropriate validation error status code). But it's a response to an XMLHttpRequest so there is no redirect to an error page. I think I actually want to do this: format.json { render :json => @comment.errors} and trigger some Javascript function that iterates through (and displays) any errors. I'm using a rails plugin http://github.com/janv/rest_in_place/ to implement the in-place editing. It doesn't appear to have any callback function to handle a failure. What are my options? Can I write some Javascript to respond to a failure condition without hacking the plugin? Do I have to hack the rest_in_place plugin to handle a failure condition? Is there a better plugin (for Rails or jQuery) that handles in-place editing, including failure conditions?

    Read the article

  • Calling web service using javascript error

    - by politrok
    Hi , I try to call webservice using json , when i call to web service without excepted parameters , its work , but when i'm try to send parameter , ive got an error : This is my code: function GetSynchronousJSONResponse(url, postData) { var xmlhttp = null; if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest(); else if (window.ActiveXObject) { if (new ActiveXObject("Microsoft.XMLHTTP")) xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); else xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } url = url + "?rnd=" + Math.random(); // to be ensure non-cached version xmlhttp.open("POST", url, false); xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8"); xmlhttp.send(postData); var responseText = xmlhttp.responseText; return responseText; } function Test() { var result = GetSynchronousJSONResponse('http://localhost:1517/Mysite/Myservice.asmx/myProc', '{"MyParam":"' + 'test' + '"}'); result = eval('(' + result + ')'); alert(result.d); } This is the error : System.InvalidOperationException: Request format is invalid: application/json; charset=utf-8. at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest What is wrong ? Thanks in advance .

    Read the article

  • How does GMail implement Comet?

    - by Morgan Cheng
    With the help of HttpWatch, I tried to figure out how GMail implement Comet. I Login in GMail with two account, one in IE and the other in Firefox. Chatting in GTalk in GMail with some magic words like "WASSUP". Then, I logoff both GMail accounts, filter any http content without "WASSUP" string. The result shows which HTTP request is the streaming channel. (Note: I have to logoff. Otherwise, never-ending HTTP would not show content in HttpWatch.) The result is interesting. The URL for stream channel is like: https://mail/channel/bind?VER=8&at=xn3j33vcvk39lkfq..... There is no surprise that GMail do Comet in IE with IFRAME. The Http content starts with " Originally, I guessed that GMail do Comet in Firefox with multipart XmlHttpRequest. To my surprise, the response header doesn't have "multipart/x-mixed-replace" header. The response headers are as below: HTTP/1.1 200 OK Content-Type: text/plain; charset=utf-8 Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Date: Sat, 20 Mar 2010 01:52:39 GMT X-Frame-Options: ALLOWALL Transfer-Encoding: chunked X-Content-Type-Options: nosniff Server: GSE X-XSS-Protection: 0 Unfortunately, the HttpWatch doesn't tell whether a HTTP request is from XmlHttpRequest or not. The content is not HTML but JSON. It looks like a response for XHR, but that would not work for Comet without multipart/x-mixed-replace, right? Is there any way else to figure out how GMail implement Comet? Thanks.

    Read the article

  • Proper DateTime Format for a Web Service

    - by user48408
    I have a webservice with a method which is called via a xmlhttprequest object in my javascript. The method accepts a datetime parameter which is subsequently converted to a string and run against the database to perform a calculation. I get the value from m_txtDateAdd and send off the xmlHttprequest <asp:textbox id=m_txtDateAdd tabIndex=4 runat="server" Width="96px" Text="<%# Today %>"> </asp:textbox> which has a validator attacted to it <asp:CustomValidator id="m_DateAddValidator" runat="server" ErrorMessage="Please Enter a Valid Date" ControlToValidate="m_txtDateAdd">&#x25CF;</asp:CustomValidator> My webmethod looks something like this [WebMethod] public decimal GetTotalCost(DateTime transactionDate) { String sqlDateString = transactionDate.Year+"/"+transactionDate.Month+"/"+transactionDate.Day; I use sqlDateString as part of the commandtext i send off to the database. Its a legacy application and its inline sql so I don't have the freedom to set up a stored procedure and create and assign parameters in my code behind. This works 90% of the time. The webservice is called on the onchange event of m_txtDateAdd. Every now and again the response i get from the server is System.ArgumentException: Cannot convert 25/06/2009 to System.DateTime. System.ArgumentException: Cannot convert 25/06/2009 to System.DateTime. Parameter name: type --- System.FormatException: String was not recognized as a valid DateTime. at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) at System.DateTime.Parse(String s, IFormatProvider provider) at System.Convert.ToDateTime(String value, IFormatProvider provider) at System.String.System.IConvertible.ToDateTime(IFormatProvider provider) at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at System.Web.Services.Protocols.ScalarFormatter.FromString(String value, Type type) --- End of inner exception stack trace --- at System.Web.Services.Protocols.ScalarFormatter.FromString(String value, Type type) at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection) at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request) at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

    Read the article

  • Comet Jetty/Tomcat, having some browser issues with Firefox and Chrome

    - by ages04
    I am exploring the use of Comet for a project I am working on. I tried creating a test application first using Tomcat6 and CometProcessor API and then with Jetty7 Continuations. The application is kind of working on both but I am having some issues with the actual display of messages. I used the technique of creating an XMLHttpRequest Connection and keeping it open all the time so the server can continuously push data to all the clients connected whenever it is available. My client side code is something similar to this: function fn(){ var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if (xhr.readyState==3){ document.getElementById('dv').innerHTML =(xhr.responseText); } if (xhr.readyState==4){ alert ('done'); } } xhr.open("GET", "First", true); xhr.send(null); } I found this thing of using readyState 3 somewhere online. I am facing 2 problems currently: In Firefox this code works perfectly. But if I open a new tab or even a new browser window, it does not make a new connection to the server and nothing shows up on the new tab or window, only the first tab/window gets the display. I used wireshark to check this and its shows only 1 connection even after the 2nd tab is opened. I am unable to understand why this would happen. I have read about the 2 connection limit, but here there is only one connection. Secondly in Chrome, the above code does not work, and the callback is not invoked for readystate of 3, only when the connection is closed by the server i get the output. I would also like to ask which is the best way/framework for doing Comet with Java. I am currently using jQuery on the client side. Any suggestions would be greatly appreciated!! Thanks

    Read the article

  • Concatenate javascript to a string/parameter in a function

    - by Gerry S
    I am using kottke.org's old JAH example to return some html to a div in a webpage. The code works fine if I use static text. However I need to get the value of a field to add to the string that is getting passed as the parameter to the function. var xmlhttp=false; /*@cc_on @*/ /*@if (@_jscript_version >= 5) try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @end @*/ if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { xmlhttp = new XMLHttpRequest(); } function getMyHTML(serverPage, objID) { var obj = document.getElementById(objID); xmlhttp.open("GET", serverPage); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { obj.innerHTML = xmlhttp.responseText; } } xmlhttp.send(null); } And on the page.... <a href="javascript://" onclick="getMyHTML('/WStepsDE?open&category="+document.getElementById('Employee').value;+"','goeshere')">Change it!</a></p> <div id ="goeshere">Hey, this text will be replaced.</div> It fails (with the help of Firebug) with the getMyHTML call where I try to get the value of Employee to include in the first parameter. The error is "Unterminated string literal". Thx in advance for your help.

    Read the article

  • Help Needed With AJAX Script

    - by Brian
    Hello All I am working on an AJAX script but am having difficulties. First, here is the script: var xmlHttp; function GetXmlHttpObject(){ var objXMLHttp=null if (window.XMLHttpRequest){ objXMLHttp=new XMLHttpRequest() } else if (window.ActiveXObject){ objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") } return objXMLHttp } function retrieveData(){ var jBossServer = new Array(); jBossServer[0] = "d01"; jBossServer[1] = "d02"; jBossServer[2] = "p01"; jBossServer[3] = "p02"; for(var i=0; i<jBossServer.length; i++){ xmlHttp = GetXmlHttpObject(); if (xmlHttp == null){ alert ("Something weird happened ..."); return; } var url="./retrieveData.php"; url = url + "?jBossID=" + jBossServer[i]; url = url + "&sid=" + Math.random(); xmlHttp.open("GET",url,true); xmlHttp.onreadystatechange = updateMemory; xmlHttp.send(null); } } function updateMemory(){ if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){ aggregateArray = new Array(); aggregateArray = xmlHttp.responseText.split(','); for(var i=0; i<aggregateArray.length; i++){ alert(aggregateArray[i]); } return; } } The "retrieveData.php" page will return data that looks like this: d01,1 MB,2 MB,3 MB They relate to my 4 servers d01, d02, p01, and p02 (dev and prod). What I am doing is scraping the memory information from http://127.0.0.1:8080/web-console/ServerInfo.jsp I want to save code so I attempted to put the AJAX xmlHttp call into a loop, but I don't think it is working. All I ever get back is the information for "p02" four times. Am I able to do what I want or do I need four different functions for each server (i.e., xmlHttpServer01, xmlHttpServer02, xmlHttpServer03, xmlHttpServer04)? Thank you all for reading, have a good day. :)

    Read the article

  • how to run XSL file using JavaScript / HTML file

    - by B. Kumar
    i want to run xsl file using javascript function. I wrote a javascrpt function which is working well with Firefox and Crom but it is not working on Internet Explorer function loadXMLDoc(dname) { if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",dname,false); xhttp.send(""); return xhttp.responseXML; } function displayResult() { xml=loadXMLDoc("NewXml.xml"); xsl=loadXMLDoc("NewFile.xsl"); // code for IE if (window.ActiveXObject) { ex=xml.transformNode(xsl); document.getElementById("example").innerHTML=ex; } // code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { xsltProcessor=new XSLTProcessor(); xsltProcessor.importStylesheet(xsl); resultDocument = xsltProcessor.transformToFragment(xml,document); document.getElementById("example").appendChild(resultDocument); } } Please help my by modifying this code or by another code so that i can work with Internet Explorer. Thanks

    Read the article

  • AJAX HTML PHP question

    - by Jordan Pagaduan
    This is my scripts.js function showHint(str) { if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } 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("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","inputProcess.php?q="+str,true); xmlhttp.send(); } This is my HTML <script type="text/javascript" src="scripts.js"></script> <form> Type your name here : <input type="text" onkeypress="showHint(this.value)" name="name" /> </form> This is my PHP file <?php $q = $_GET['q']; $dbc=mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db('input_oop') or die (mysql_error()); $sql = "INSERT INTO users set name = '".$q."'"; mysql_query($sql) or die (mysql_error()); ?> When the text is save in my database it will save 5 times or up.

    Read the article

  • response.Text is undefined when returning variable

    - by George
    Not sure if the problem is related to Ajax or something silly about JavaScript that I'm overlooking in general, but I have the following script where fox.html is just plain text that reads, "The quick brown fox jumped over the lazy dog." : function loadXMLDoc() { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","fox.html",true); xmlhttp.send(); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { fox = xmlhttp.responseText; alert(fox); } } } onload = loadXMLDoc; The above script alerts the contents of fox.html onload just fine. However if I change the script so that: { fox = xmlhttp.responseText; alert(fox); } becomes: { fox = xmlhttp.responseText; return fox; } and alert(loadXMLDoc()); onload I get 'undefined'. I'm wondering why this is so.

    Read the article

  • innerHTML in IE?

    - by froufrou
    I'm having trouble using innerHTML with my radio type button. <table align="center"> <div class='main'> <span id="js" class='info'> <label><input type="radio" name="js" value="0" size="<?php echo $row['size']; ?>" onclick="js(this.value, this.size);" /><img src="arrowup.png"/></label> <br /> <label><input type="radio" name="js" value="1" size="<?php echo $row['size']; ?>" onclick="js(this.value, this.size);" /><img src="arrowdown.png"/></label> </span> </div> </table> My .js looks like this: var xmlhttp; function getVote(a,b) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="js.php"; url=url+"?js="+a; url=url+"&id="+b; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("js").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { var objXMLHttp=null; if (window.XMLHttpRequest) { objXMLHttp=new XMLHttpRequest(); } else if (window.ActiveXObject) { objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP"); } return objXMLHttp; } This doesn't work in IE only! Any help?

    Read the article

  • restrict script inside iframe to run only within pages of same top-level domain?

    - by Justin Grant
    I'd like to enforce a requirement that client script inside a page (which in turn is loaded inside an iframe of another page) will only run when the parent page is on the same top-level domain as the framed page (although it may be on another hostname in that domain). Is this do-able? I assume that the easy solution of looking at top.location.host won't be available due to cross-site scripting limitations, but I'm wondering if other javascript hackery could suffice. Constraints on any potential solution inculde: I need to be able to run XmlHttpRequest calls inside the child page, and I need to validate that the hostname is in the same domain before I make those calls. (this makes a document.domain solution challenging because AFAIK setting document.domain disables the ability to make XmlHttpRequest calls. I can control client-side script and HTML on both parent or child (and I can create new pages if needed), but I can't make any server-side code changes. I can't simulate the above via server-side calls or proxies, because the child page's hostname uses a forms auth system with hostname-scoped cookies that I can't get access to from the parent page since it's on a different hostname. I don't have enough control over the child-frame site to be able to put both sites behind the same reverse-proxy or load-balancer (which would enable me to put both sites on the same hostname). I don't actually need to access any UI inside the IFrame-- the iframe is invisible and I'm only using it to run javascript within the security context of a site on a different hostname from the parent page. So at this point I'm stumped. Got any ideas? I want to make sure I'm not overlooking an easy solution before giving up.

    Read the article

  • Ajax function partially fails when alert removed

    - by YsoL8
    Hello. I have a problem in the following code: //quesry the db for image information function queryDB (parameters) { var parameters = "p="+parameters; alert ("hello"); 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) { // use the info alert (xmlhttp.responseText); } } xmlhttp.open("POST", "js/imagelist.php", true); //Send the proper header information along with the request xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", parameters.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(parameters); } When I remove the alert statement 4 lines down I hit problems. This function is being called by a loop, and without the alert, I only get results for the last value sent to the statement. With it, I get everything I was expecting and really I'm at a loss to know why. I've heard that this may be a timing issue as I'm sending new requests before the old one is finished. I also heard polling being mentioned, but I can't find any information detailed enough. I'm new to synchronous services and I'm not really aware of the issues.

    Read the article

  • Executing javascript script after ajax-loaded a page - doesn't work

    - by Deukalion
    I'm trying to get a page with AJAX, but when I get that page and it includes Javascript code - it doesn't execute it. Why? Simple code in my ajax page: <script type="text/javascript"> alert("Hello"); </script> ...and it doesn't execute it. I'm trying to use Google Maps API and add markers with AJAX, so whenever I add one I execute a AJAX page that gets the new marker, stores it in a database and should add the marker "dynamically" to the map. But since I can't execute a single javascript function this way, what do I do? Is my functions that I've defined on the page beforehand protected or private? ** UPDATED WITH AJAX FUNCTION ** function ajaxExecute(id, link, query) { if (query != null) { query = query.replace("amp;", ""); } 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) { if (id != null) { document.getElementById(id).innerHTML=xmlhttp.responseText; } } } if (query == null) { xmlhttp.open("GET",link,true); } else { if (query.substr(0, 1) != "?") { xmlhttp.open("GET",link+"?"+query,true); } else { xmlhttp.open("GET",link+query,true); } } xmlhttp.send(); }

    Read the article

  • php not redirecting

    - by NSchulze
    I'm trying to write the logout of a website. When I do this I want the page to redirect to the login page. I think I'm doing it the correct way, but can't get the right result. Could you guys point me in the right direction? Relevant Code: <button onclick="logout()">Logout</button> function logout() { 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.location=xmlhttp.responseText; } } xmlhttp.open("GET","logout.php",true); xmlhttp.send(); } <?php session_destroy(); header("Location:http://localhost:8888/loginns.html"); mysql_close($con); ?> Thanks!

    Read the article

  • javascript ajax help

    - by ngreenwood6
    I have the following code. var d3_ad = 1; function displayD3Ad(){ var query_string = '?d3_ad='+d3_ad; query_string += '&location='+escape(location); //document.write('<iframe src="index.php'+query_string+'"></iframe>'); var data = httpRequest('http://localhost/test/index.php','GET',query_string); document.write(data); } function httpRequest(strURL,type,query) { var request = false; if (window.XMLHttpRequest) {// Mozilla/Safari request = new XMLHttpRequest(); } else if (window.ActiveXObject) { //Internet Explorer request= new ActiveXObject("Microsoft.XMLHTTP"); } request.open(type, strURL + query, true); request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); request.onreadystatechange = function() { if (request.readyState == 4) { return request.responseText; } } request.send(null); } displayD3Ad(); now when it writes out the data it is saying undefined. It seems like it isnt returning the data. I looked in firebug and it completes and shows the response that shoudl be there. Any help is appreciated. I just need to set the data variable so that I can use it later on.

    Read the article

  • jQuery.ajax() + empty JSON object = parse error

    - by roosteronacid
    I get a parse error when using jQuery to load some JSON data. Here's a snippet of my code: jQuery.ajax({ dataType: "json", success: function (json) { jQuery.each(json, function () { alert(this["columnName"]); }); } }); I get no errors when parsing a non-empty JSON object. So my guess is that the problem is with my serializer. Question is: how do I format an empty JSON object which jQuery won't consider malformed? This is what I've tried so far, with no success: {[]} {[null]} {} {null} {"rows": []} {"rows": null} {"rows": {}} UPDATE: I can understand that I've been somewhat vague--let me try and clarify: Parsing of the JSON object is not the issue here--JQuery is - I think. jQuery throws a parse-error (invokes the error function). It seems like jQuery's internal JSON validation is not accepting any of the before mentioned objects. Not even the valid ones. Output of the error function is: XMLHttpRequest: XMLHttpRequest readyState=4 status=200 textStatus: parsererror errorThrown: undefined This goes for all of the before mentioned objects.

    Read the article

  • jQuery and Ajax

    - by Banderdash
    Can anyone help with a jQuery snippet that would use Ajax to pull an XML file in on page load? Have really clunky way of doing it without jQuery here: <script type="text/javascript"> function loadXMLDoc() { 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) { xmlDoc=xmlhttp.responseXML; var txt=""; x=xmlDoc.getElementsByTagName("title"); for (i=0;i<x.length;i++) { txt=txt + x[i].childNodes[0].nodeValue + "<br />"; } document.getElementById("checkedIn").innerHTML=txt; } } xmlhttp.open("GET","ajax-response-data.xml",true); xmlhttp.send(); } </script> Ideally rather the having a click generate the list it would do so on page load, showing the fields from the XML (title, author, and whether it is checked in or not i.e. <book id="#" checked-in="0">) Would hug you for a solution.

    Read the article

  • Unable to send '+' through AJAX post?

    - by Harish Kurup
    I am using Ajax POST method to send data, but i am not able to send '+'(operator to the server i.e if i want to send 1+ or 20k+ it will only send 1 or 20k..just wipe out '+') HTML code goes here.. <form method='post' onsubmit='return false;' action='#'> <input type='input' name='salary' id='salary' /> <input type='submit' onclick='submitVal();' /> </form> and javascript code goes here, function submitVal() { var sal=document.getElementById("salary").value; alert(sal); var request=getHttpRequest(); request.open('post','updateSal.php',false); request.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); request.send("sal="+sal); if(request.readyState == 4) { alert("update"); } } function getHttpRequest() { var request=false; if(window.XMLHttpRequest) { request=new XMLHttpRequest(); } else if(window.ActiveXObject) { try { request=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { request=new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { request=false; } } } return request; } in the function submitVal() it first alert's the salary value as it is(if 1+ then alerts 1+), but when it is posted it just post's value without '+' operator which is needed... is it any problem with query string, as the PHP backend code is working fine...

    Read the article

  • How to add on key down and on key up event in java script

    - by Ramesh
    Hello , I am creating an live search for my blog..i got this from w3 schools and i need to add on keyboard up,down mouse up and down event ... <html> <head> <script type="text/javascript"> function showResult(str) { if (str.length==0) { document.getElementById("livesearch").innerHTML=""; document.getElementById("livesearch").style.border="0px"; return; } 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("livesearch").innerHTML=xmlhttp.responseText; document.getElementById("livesearch").style.border="1px solid #A5ACB2"; } } xmlhttp.open("GET","livesearch.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form> <input type="text" size="30" onkeyup="showResult(this.value)" /> <div id="livesearch"></div> </form> </body> </html>

    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

  • ASP.NET Web Service returning XML result and nodevalue is always null

    - by kburnsmt
    I have an ASP.NET web service which returns an XMLDocument. The web service is called from a Firefox extension using XMLHttpRequest. var serviceRequest = new XMLHttpRequest(); serviecRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); I consume the result using responseXML. So far so good. But when I iterate through the XML I retrieve nodeValue - nodeValue is always null. When I check the nodeType the nodeType is type 1 (Node.ELEMENT_NODE == 1). Node.NodeValue states all nodes of type Element will return null. In my webservice I have created a string with the XML i.e. xml="Hank" I then create the XmlDocument XmlDocument doc = new XmlDocument(); doc.LoadXML(string); I know I can specify the nodetype using using CreateNode. But when I am just building the xml by appending string values is there a way to change the nodeType to Text so Node.nodeValue will be "content of the text node".

    Read the article

  • Javascript document.open asynchronous?

    - by Alex Schneider
    So on my site there is a Javascript function that will load a new site from the server via XMLHttpRequest. After that it replaces the current page with the new one: var post = new XMLHttpRequest(); post.open('POST', data); post.onload = function() { var do = document.open("text/html", "replace"); do.write(post.responseText); do.close(); goOn(); } function goOn() { console.log($('img:visible')); } Some could assume that after do.close() the document has changed and is ready. But it is not, e.g. if i load very much/big data/responseText the function goOn() only logs an empty result. Obviously goOn() gets in that case called before the DOM is ready to be read! Unfortunately the is no "ready" event fired after write() finished.... How can i be sure it is finished? /EDIT: goOn() logs this to Chrome Console: [prevObject: p.fn.p.init[1], context: #document, selector: "img:visible"] context: #document length: 0 prevObject: p.fn.p.init[1] selector: "img:visible" __proto__: Object[0] But if i right after that type $('img:visible') into console manually it shows me all images....

    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

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >