PDA

View Full Version : can ASP be used inside jQuery?



isntworkdull
07-30-2010, 10:38 AM
Hi all

I was trying to add a simple link to some products on my site, the link was going to the products main page.

the link uses the .asp code
<%=rs("pID")%> to go to the product page...

below is the jquery i tried to use:


;$(function(){
$('div.prodprice').after('<p class="no_space" align="center">
<a class="ectlink" href="../proddetail.asp?prod=<%=rs("pID")%>">
<img src="../images/imgconfopts.gif" alt="View Details" width="115px" border="0" />
</a></p>')
});

it doesnt work, the link seems to break at the first " inside
<%=rs("pID")%>

does anyone know a way around this?

thanks
James

djr33
07-30-2010, 01:40 PM
ASP processes and generates the page, then sends this to the browser. After that, Javascript runs in the browser.
The two cannot function at the same time.

Are you trying to set an initial value in ASP for the JS? This is possible. If this is not working, there must be an error in your ASP-- you might want to post in the ASP forum about that.

But if you are trying to continuously use ASP through the JS, that will never work like that because of the way that ASP is processed first, then JS.
In order to do that, you will need to use "Ajax", which is a method of loading/requesting extra data (pages) from the server through JS without reloading the page (just loading a new page in the background that the user sees as part of the same page).

jscheuer1
07-31-2010, 03:30 AM
The short answer to your question is yes.

If this is a one time insertion as the page is loading, one way to debug it is to view the page or script (if it's an external script) in the browser. IE will not view external scripts, so use another browser if it's an external script.

Anyways, viewing in the browser will, in the case of a page allow you to use the browser's 'view source'. This will show you how your asp token (<%=rs("pID")%>) is being served to the user. In the case of an external script, in just about any browser other than IE, navigating directly to the external script will show you how that script is being served.

Once you see how the code is being served, it should be relatively easy to see what's causing the problem. In a case like this, often it's missing or extra quotation marks. But it could be numerous things.

Remember, regardless of what asp token you use, it must resolve in the served code to fit what is expected in the javascript.

If you want more help:

Please post a link to a page on your site that contains the problematic code so we can check it out.