开发者

AJAX and ASP Image Loading Problems

Im working on a production interface and im need to load some images. Im working in jsp mainly but using AJAX to request the images.

The AJAX itself works, if I create an HTML page with a simple:

<div id='holding'><im开发者_StackOverflow中文版g id='myImage' src='images/image.png' alternate='check' width='64' height='64' /></div>

and request it through the AJAX method the image loads and displays fine by setting something's inner.HTML to the response. I want to be able to change the source path dynamically so in asp i've created:

    <%
        x=Request.QueryString("x")
        y=Request.QueryString("y")

        Response.Write("<div id='holding'><img id='myImage' src='"&x)
        Response.Write("'alternate='"&y"' width='64' height='64' /></div>")
%>

Now when I call my ajax with a query string I no longer get my image loading.

var src = 'images/image.png';
    var alt = 'check';
    var queryString = "?x="+src+"&y="+alt;

    xmlhttp.open("GET", url + queryString, true);
    xmlhttp.send();

Ideas?


I have discovered the problem here. Besides a few typos and syntax errors here and there the major issue was that ASP was not installed on the server I was accessing, we use a lot of .asp scripts but they are all tied to a different server.

One issue in particular that would follow to any language is that my queryString contained a '/' that I had not 'escaped'. This has been replaced with '%5c'

Since my work is in JSP anyway I decided to rebuild this using that, what follows is the scriptlet I used to load my images, saved as a .jsp and written in regular java, I call this with my AJAX method and it works beautifully:

<%
String source = request.getParameter("src");
String alternate = request.getParameter("alt");
    out.println("<img border='0' src='"+source+"' alt='"+alternate+"' width='128' height='128' />");
%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜