I can't remember where I read it, but I thought that doing
$( function(){
//code here
});
Would make the code execute on page load?
However, it seems that the above function only fires if I also include
$(document).ready(function(){
//code here
});
I have tried searching on this, but Google doesn't give me any relevant results, and the search for this forum seems to return results, but doesn't display them.
The request is made successfully and a response returned from the server, but the error handler is called rather than the success handler.
For the error in question, this prints:
Error:
textStatus: error
errorThrown:
jqXHR.status: 0
jqXHR.statusText: error
Printing jqXHR.responseText to the page shows that jquery has received the response OK, though it is difficult to see exactly what jqXHR.responseText contains as it has some html in it, which is converted to html when printed rather than being displayed as plain text.
Using Fiddler to debug the request, the headers of the response are:
HTTP/1.1 200 OK
Server: nginx/0.7.64
Date: Wed, 30 Nov 2011 17:04:22 GMT
Content-Type: application/json
Connection: keep-alive
X-Powered-By: PHP/5.3.4
Vary: Accept-Encoding
Cache-Control: private, must-revalidate
Content-Length: 21593
and the response body validates as valid JSON using http://jsonlint.com/, so I can't work out why the AJAX request is 'failing'.
Is there any way I can get more info on what the actual error is?
I have a function that resizes an image (imgCur) and changes its padding when a new image (img) is loaded like so: img.onload = function(){ var t = this; //Animate current image to new image size imgCur.animate({ "width": t.width, "height": t.height, "padding": "20px 25px" }, 750).attr("src", img.src); } Which works fine in FF, Opera and Chrome. But in IE6, 7 & 8 it doesn't like changing the padding, and I get an error at line 835 in jquery-1.3.2.js, which is: style.left = ret || 0; If I check in the IE Script debugger, ret has the value "40px 50px", which obviously isn't a valid value for style.left. "40px 50px" is the padding of imgCur that is set in the CSS file. But why is jQuery trying to set the CSS left property of imgCur to its current padding?
I have the following code: <code><pre>var depth = 2; var name = 'category' + depth; var html = $('<div class="indent">' + "\n<p>\n" + '<label for="' + name + '">Sub Category:</label> ' + '<select id="' + name + '" name="' + name + '">' + "\n" + '<option value="none">Select a sub category</option>' + "\n" + '<option value="0">Add new sub category</option>' + "\n" + "</select>\n</p>\n</div> \n"); alert($(html).children('p')[0].nodeName);</pre></ code> In FF, IE7 and Safari it will alert 'p', but in Opera (tested 9.64 and 10Alpha1) I just get an error in the Error Console: <code><pre>JavaScript - http://photosite.com/upload Timeout thread: delay 13 ms Error: name: TypeError message: Statement on line 21: Cannot convert undefined or null to Object Backtrace: Line 21 of linked script http://photosite.com/CSI/js.js alert($(html).children('p')[0].nodeName); Line 19 of linked script http://photosite.com/CSI/jquery-1.3.2.min.js: In function I function I(){if(M.success){M.success(V,R)}if(M.global) {o.event.trigger("ajaxSuccess",[J,M])}} Line 19 of linked script http://photosite.com/CSI/jquery-1.3.2.min.js function(X){if(J.readyState==0){if(P){clearInterval(P);P=null;if (M.global&&!--o.active){o.event.trigger("ajaxStop")}}}else{if(!K&&J&& (J.readyState==4||X=="timeout")){K=true;if(P){clearInterval(P);P=null} R=X=="timeout"?"timeout":!o.httpSuccess (J)?"error":M.ifModified&&o.httpNotModified (J,M.url)?"notmodified":"success";if(R=="success"){try{V=o.httpData (J,M.dataType,M)}catch(Z){R="parsererror"}}if(R=="success"){var Y;try {Y=J.getResponseHeader("Last-Modified")}catch(Z){}if(M.ifModified&&Y) {o.lastModified[M.url]=Y}if(!W){I()}}else{o.handleError(M,J,R)}L();if (X){J.abort()}if(M.async){J=null}}}} ... stacktrace: n/a; see 'opera:config#UserPrefs|Exceptions Have Stacktrace'</pre></code> If I run the code in the Command Line in Opera Dragonfly it just gives the error: <code>Cannot convert undefined or null to Object</code> Can anyone help me with this? (I couldn't find any info on if this message will be encoded as html or plain text, but in the event it comes out as plain text, you can see the code snippets here: http://www.thewebsqueeze.com/forum/Javascript-f66/Jquery-Function-Not-Working-In-Opera-t4371.html) Thanks Dave