I've got a page that is using jQuery.
$("#start_date").val()
The above code returns the value of an box just fine on the Apache server. However, in IIS, it returns "undefined."
Are there special setup considerations that are needed for an IIS deployment of jQuery?
EDIT #1
I might also point out that this is using the jQuery datepicker. Other fields on the page which are just standard text boxes work fine.
EDIT #2
Ok, so I narrowed this down a bit more. The tag for this date is defined like this:
id="add_start_date" name="start_date"
When I change it to this:
id="start_date" name="开发者_高级运维start_date"
It works fine. Why the difference between the servers? It doesn't seem like this should make any difference at all.
It is simply not possible for a feature of jQuery to be dependent upon your choice of web server.
It IS possible that different web servers are providing different HTML markup as a previous poster suggested, but then the problem is you're running jQuery against different sets of HTML. jQuery itself is executed entirely within the browser making the only realistic differences browser-based differences.
I know that's not reassuring, I just want you to realize you're barking up the wrong tree. :/
Take a look at the source generated from your Apache server and compare it to the source generated from the IIS server. Also, see if you can use a WebKit browser (Safari or Chrome) or maybe Firefox to see if the JavaScript files are being transferred.
Make sure that the jQuery script file is in a location that is accessible to the page - you can check to see if jQuery is present by testing for window.$
(assuming no other definition for $
exists).
The problem is most likely that in an ASP.NET application, the actualy id of the element is not start_date
for a server control with that id. When a server control is inside a container, the container id is prepended to the control id to keep it unique.
You can get the generated id using the ClientID property:
var id = '<%=start_date.ClientID%>';
The you use the name in the jQuery code:
$('#'+id).val()
Have you checked that the HTML is the same and that there is definitely an element (and only one) with an ID of start_date
?
If it's not that, make sure that the jQuery code is being included properly. A good test is to add alert('hello')
to the file - if you get the alert, the file is being included.
精彩评论