0

I try to run the below javascript code but it does not work. (it does not return the alert pop up) I put the url string into a browser, it return the item info. So, I assume the url is fine. And the server return the information I want.

URL to brower:

/_api/web/lists/getbytitle('<Listname>')/items(1)/AttachmentFiles/

Returns:

<?xml version="1.0" encoding="utf-8"?><feed xml:base="myurl/_api/"; xmlns="w3.org/2005/Atom"; xmlns:d="schemas.microsoft.com/ado/2007/08/dataservices"; xmlns:m="schemas.microsoft.com/ado/2007/08/dataservices/metadata"; xmlns:georss="georss.org/georss"; xmlns:gml="opengis.net/gml">
    <content type="application/xml">
        <m:properties>
            <d:FileName>attached_filename.csv</d:FileNa‌​me>
            <d:ServerRelativeUrl>/DART/Lists/test/Attachments/1/attached_filename.csv</d:S‌​erverRelativeUrl>
        </m:properties>
    </content>
</entry></feed>

But why the code stop here? What is wrong? in the code? in the server? Any help is appreciated. Thank you so much!

$.ajax({
    type: "GET",
    url: url + "/_api/web/lists/getbytitle('" + name + "')/items(" + id + ")/AttachmentFiles/",
    headers: {
      "accept": "application/json;odata=verbose",
      "content-type": "application/json;odata=verbose"
    },
    success: function(data) { alert('succ');},
    error: function() {alert('err');}
  });

I am including the following before the script:

<script type="text\javascript" src="code.jquery.com/jquery-1.11.3.min.js">; </script>

After I looked into the error info, I found the $ is underfined error. Any idea why? How can I defined $? Thanks! SCRIPT5009: '$' is undefined it is near the ajax.

1
  • Comments are not for extended discussion; this conversation has been moved to chat. Commented Aug 28, 2015 at 9:02

1 Answer 1

0

Remove the semi-colon from your jquery definition tag. It should look something like:

<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

Text between tags that should reference external scripts will mess things up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.