Using jQuery with ASP.NET: Part 2 - Making Ajax Callbacks to the Server - 1 views
-
$.getJSON(url,data,callback) Similar to $.post(), but expects the result to be JSON which is automatically deserialized into a Javascript value and passed to the callback as a parameter.
-
$.getJSON() also doesn’t support JSON POST data – only POST encoded variables
-
Specifically inside of a master page you might find that the ID gets mangled by ASP.NET into: ctl00_Content_txtSymbol. I could change my code to read: { symbol: $("#ctl00_Content_txtSymbol").val() } which works, but is pretty ugly and volatile because the parent IDs might change if a container is renamed or moved around. Another option is to use a little server side script markup to embed the ClientID: { symbol: $("#<%= txtSymbol.ClientID %>").val() } This is also ugly, but reliable. But this does not work if you end up moving your code into a separate .js script file. If you use client ids like this a lot you might create a list of them as global variables: var txtSymbolId = "<%= txtSymbol.ClientID %>"; which then lets you reuse the variable a little more easily: { symbol: $("#" + txtSymbolId).val() } These variables are also visible in loaded script files.
- ...4 more annotations...