using jquery to check if a pdf file exists on the server... .load()?
hi guys,
i'm new to this jquery stuff. I am looking for a solution for the problem described above. In the given case i am building a dynamic from where a user can enter 2 inputvalues and should then be provided with a link for a pdf file.
to get this thing right, i need to check if a file exists on the server while the user is typing.
see following method:
- function getPDFLink() {
- var a=document.getElementById("pk").value;
- var b= document.getElementById("folge").value;
-
- if(a.length = 15 && b.length == 3) {
- // static way without check
- document.getElementById("pdfLnk").innerHTML = "<a href="fileadmin/pdffiles/"+a+b+".pdf" target='blank'>PDF anzeigen</a>";
- /dynamic way fails
- $(".pdflink").load("fileadmin/pdffiles/"+a+b+".pdf", function(response, status, xhr) {
- if (status == "error") {
- var msg = "Sorry but there was an error: ";
- $(".pdflink").html(msg + xhr.status + " " + xhr.statusText);
- }
- });
- }
- }
now here's the point. I dont want the pdf to be loaded in the <a> tag. i want to evaluate the response values and provide a link when 200 is returned... otherwise a errormessage should be shown.
i hope you guys can help me with this one.
kind regards
michael