-
Posts
445 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by tinfanide
-
-
Yes, thanks for your codes.I was doing JSON.parse but after success, I just thought that whether it would be faster if the json data is parsed into a string.As I need to loop through the json array (stored in a .JSON file) for searching purposes through AJAX, that's why I want to test if a JSON string is faster than looping through an array.is there a reason you can't convert the string into JSON and then access it as an array? some browsers support it natively, if not Douglas Crockford has a library.https://github.com/d...ockford/JSON-jsvar string = "[{"Title": "Book4","Barcode": "bk4","Location": "Lib4"},{"Title": "Book4","Barcode": "bk4","Location": "Lib1"}]";var json = JSON.parse(string);console.log(json[0]);
-
Ya just inspired me. Yes, ya're very right.Otherwise, the pattern would be to match a "{" character, then any number of characters that are not "}", then "}".// IE7+ returns:// FF9 returns:found = jsonData.match(/{[^{]*Lib4[^}]*}/i);
-
I want to extract"[{"Title": "Book4","Barcode": "bk4","Location": "Lib4"},{"Title": "Book4","Barcode": "bk4","Location": "Lib1"}]"
Have tried:{"Title": "Book4","Barcode": "bk4","Location": "Lib4"}str.match(/[\W]*Lib4[\W]*/);
but return nothing. How can I take it out with JavaScript Regular Expression?
-
Then I just stick to using <table>.Thanks for pointing to the reference. Quirksmod is always a good one.According to compatibility research, table, table-row and table-cell are only supported on Internet Explorer 8 and above.http://www.quirksmod...ss/display.html -
But it really doesn't work in IE7,display: table-row will work on any element. The point of the display property is to make an element behave like something it is not.The <tr> element doesn't need "display: table-row" because it already is a table row.<style>.form_style{display: table-cell;width: 250px; height: 40px;}</style></head><body><form name="queries"><div style="display: table;"><div style="display: table-row;"><div class="form_style"><input type="checkbox" name="libraries" value="Lib1" />Lib1<input type="checkbox" name="libraries" value="Lib2" />Lib2<input type="checkbox" name="libraries" value="Lib3" />Lib3<input type="checkbox" name="libraries" value="Lib4" />Lib4<br /><input type="checkbox" name="items" value="Title" />Title<input type="checkbox" name="items" value="Barcode" />Barcode</div><div class="form_style"><input type="input" name="query" value="" /></div></div></div></form>
-
If I'm remembering correctly, for the table-cell to display properly, it needs to be wrapped in an element with table-row display which is wrapped in another element with table display.
<form name="queries"><table style="display: table; height: 50px;"> <tr style="display: table-row;"> <td style="display: table-cell; width: 250px;"> <input type="checkbox" name="libraries" value="Lib1" />Lib1 <input type="checkbox" name="libraries" value="Lib2" />Lib2 <input type="checkbox" name="libraries" value="Lib3" />Lib3 <input type="checkbox" name="libraries" value="Lib4" />Lib4 <br /> <input type="checkbox" name="items" value="title" />Title <input type="checkbox" name="items" value="barcode" />Barcode </td> <td style="display:table-cell; width: 100px;"> <input type="input" name="query" value="" /> </td> </tr></table></form>
Yes, you are right. But display: table-row only goes with <table>, not <div>.
-
var b = true;window.onload = function(){(b==true) ? function(){ var c = "Hello!"; func(c); } : null ;}function func(c){document.write("The word is " + c);}
It seems that the function cannot be loaded in this tenary operator.Why's that?
-
<div><form name="queries" style="display: table;"><div style="display: table-cell; width: 250px; height: 200px;"><input type="checkbox" name="libraries" value="Lib1" />Lib1<input type="checkbox" name="libraries" value="Lib2" />Lib2<input type="checkbox" name="libraries" value="Lib3" />Lib3<input type="checkbox" name="libraries" value="Lib4" />Lib4<br /><input type="checkbox" name="items" value="title" />Title<input type="checkbox" name="items" value="barcode" />Barcode</div><div style="display:table-cell; width: 100px; height: 200px;"><input type="input" name="query" value="" /></div></form></div>
Any IE8- (in my case IE7) fix for not displaying the table-cells properly?
-
How's a callback function like?Is it to check the readyState and status of the first AJAX request before going to the second one?declare it outside of the function scope. i.e.<script>var oJSON, sJSON;..
however, if you plan on using the value of sJSON across two asynchronous requests (with the second being dependent on the first), you would probably want to make the second AJAX request as part of the callback function of the first. (at that point it won't need to be global though).
-
Solve it.It should bevar ajax = function(query){xmlhttp = (window.XMLHttpRequest) ? xmlhttp=new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Msxml2.XMLHTTP") : null ;xmlhttp.onreadystatechange = function(){ jsonData = JSON.parse(xmlhttp.responseText); (xmlhttp.readyState==4 && xmlhttp.status==200) ? func(query) : null ; }xmlhttp.open("GET","lib.json",true);xmlhttp.send();} function func(query){ // fail to check an undefined AJAX responseText if(typeof(xmlhttp.responseText)=="undefined" && xmlhttp.responseText != null){ alert(0); }else { document.getElementById("result").innerHTML = jsonData[1][query]; }}
This is the testing page:http://lifelearning....st.com/lib.html Just wanna ask how to check an undefined AJAX responseText.Many thanks.
if (typeof(jsonData[1][query])!=="undefined" && (jsonData[1][query])!=null){ // something}
not jsonData or xmlhttp.responseText that should not be null or "undefined"
-
var ajax = function(query){xmlhttp = (window.XMLHttpRequest) ? xmlhttp=new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Msxml2.XMLHTTP") : null ;xmlhttp.onreadystatechange = function(){ jsonData = JSON.parse(xmlhttp.responseText); (xmlhttp.readyState==4 && xmlhttp.status==200) ? func(query) : null ; }xmlhttp.open("GET","lib.json",true);xmlhttp.send();} function func(query){ // fail to check an undefined AJAX responseTextif(typeof(xmlhttp.responseText)=="undefined" && xmlhttp.responseText != null){ alert(0); }else { document.getElementById("result").innerHTML = jsonData[1][query]; }}
This is the testing page:http://lifelearning.xtreemhost.com/lib.html Just wanna ask how to check an undefined AJAX responseText.Many thanks.
-
<html><!--php_json.php--><head><script src="json2.js"></script><script src="php.js"></script><script>ajax("php_json.json",function(){oJSON = JSON.parse(xmlhttp.responseText);sJSON = JSON.stringify(oJSON);/*put it hereokay*/});// here, the variable sJSON is undefinedajax("php.php?json="+sJSON,function(){ alert(xmlhttp.responseText); });//</script></head><body></body></html>
// php.jsfunction ajax(source,func){xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Msxml2.XMLHTTP") : null ;xmlhttp.onreadystatechange = function(){ (xmlhttp.readyState == 4 && xmlhttp.status == 200) ? func() : null ; }xmlhttp.open("GET",source,true);xmlhttp.send();}
wanna ask how to extend the scope of the variable sJSON to be global?
-
Yes.But I tried clearing the cache and cookies (even for the domain)After the four clear options were checked,there was still nothing that changed.I thought it would be to do with the history setting where I now disable the histroy record option.
-
Yes, something to do with the history setting in IE9.Thank you.delete your history, and change the settings around to suit you -
When testing a webpage,I use IE9 Web Developer (press F12). Say,The first time I did something in Dreamweaver that uploaded the file later to the server. I pressed F12 andIE9 poped out and showed the result.I came back to DW and changed the codes a bit and came back to IE9.This time no matter how many times I had pressed F5 to refresh the webpage, it still stayed on the first result without changing. This does not happen ever in Firefox Console.Could there be a fix for this IE9 problem?
-
Yes, both work.To work with falsevar elem = "ThisElementID" function ajax() { xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Msxml2.XMLHTTP") : null ; xmlhttp.onreadystatechange = function() { if(this.readyState == 4 && this.status == 200) { jsonData = eval("("+xmlhttp.responseText+")"); } } xmlhttp.open("GET","json.json",false); // with false it pauses until value is returned before proceeding which may cause older browsers to lock. xmlhttp.send(null); return jsonData[1][2]; } window.onload= function() { document.getElementById(elem).innerHTML = ajax(); }
another option
var elem = "ThisElementID" function ajax() { xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Msxml2.XMLHTTP") : null ; xmlhttp.onreadystatechange = function() { if(this.readyState == 4 && this.status == 200) { jsonData = eval("("+xmlhttp.responseText+")"); document.getElementById(elem).innerHTML = jsonData[1][2]; } } xmlhttp.open("GET","json.json",true); xmlhttp.send(null); } window.onload= function() { ajax() }
-
Changin true to false (asyn) does not work. Yes, using a callback does the work. I didn't know how to use a callback, though.Just still don't understand why it works like return and why return does not work in this case.Just a typo (GetJsonData -> getJsonData)Thank you.
-
The problem lies in, in my honest opinion, the way I return the xmlhttp.responseText.Just ask for help on how to return an ajax object.
function ajax(){xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Msxml2.XMLHTTP") : null ;xmlhttp.onreadystatechange = function(){ var jsonData = eval("("+xmlhttp.responseText+")"); (this.readyState == 4 && this.status == 200) ? alert(jsonData[0][0]) : null ;}xmlhttp.open("GET","json.json",true);xmlhttp.send(null);}
This does the job, though.
-
<script>function ajax(){xmlhttp = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP") ? new ActiveXObject("Msxml2.XMLHTTP") : null ;xmlhttp.onreadystatechange = function(){ var jsonData = eval("("+xmlhttp.responseText+")"); return (this.readyState == 4 && this.status == 200) ? jsonData[1][1] : null ;}xmlhttp.open("GET","json.json",true);xmlhttp.send(null);} window.onload function func(){document.getElementById(elem).innerHTML = ajax(); // return undefined}</script>
Is there a syntax mistake that produces the undefined result?// json.json[ ["http://hk.yahoo.com","Yahoo HK","News"], ["http://www.google.com","Google","Search Engine"],] -
if (object.focused = true) {// do something}
Is there a way to check if an element is focused in JavaScript?
if(obj!==null): why can't check the null value?
in JavaScript
Posted
Please kindly go tohttp://lifelearning.xtreemhost.com/lib.htmlA testing page. Just check the checkbox "Lib1" and do not enter anything in the input boxI have checked if sFound1 is null in the if condition (already commented in the codes,but the table (at the bottom) still returns the null value. Can anyone help me a bit here?Many thanks in advance.