How do I pass data from c# to jquery/javascript? -
i have function i'd run when page loads, either in document.ready or pageload.
using jquery, i'll trigger function using class name
in document.ready
var span = $('.linkify'); span.html(texttolinks(span.html()));
elsewhere
function texttolinks(text) { var exp = /(my text)/ig; return text.replace(exp, "<a class='link' href='http://www.bbc.co.uk' target='_blank' >$1</a>");
}
now works simple test data, need work out how expand functionality.
i have list of terms in c# app, along relevant url. i'm thinking of passing data string, , splitting in, javascript knowledge has lot of holes.
so suppose have 3 questions:
- how string function when page loaded?
- is string right type or can pass other dictionary object?
- how iterate through each of terms passed efficiently?
thanks in advance.
@anand correct saying can use jquery ajax retrieve server-side data.
however, depending on want do, might able way.
you can use .net javascriptserializer
class serialize data json format. json tool become familiar if aren't familiar it.
javascriptserializer
put json in string, can put inside hidden input , read javascript code. has advantage there no need second http request, case jquery ajax.
Comments
Post a Comment