0

I am trying to get my phone number by getting xml info from xml website. The xml website was able to detect my userID computer and gave me a list of my profile included my phone number.

Here is example of xml displayed,

<MyData>
 <user>
   <uid>U580784</uid>  
   <sn>Bell</sn> 
   <givenName>James</givenName> 
   <initials>B</initials>  
   <Company>Happy Company</Company> 
   <Department>IT</Department>  
   <co>UNITED STATES</co>  
   <telephoneNumber>888-888-8888</telephoneNumber> 
 </user>
</MyData>

I want JQuery AJAX to get telephone number from <telephoneNumber> and display on alert box.

However I keep getting Ajax error thrown from error alert. Do I miss something?

you will see a xml link in AJAX below that have unique search UserID=me mean only detect when access to website or I can replace to UserID=U555555 to get other person phone number.

Here is my Jquery and asp codes,

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js" type="text/javascript"></script>
   <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
   <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<script language="javascript" type="text/javascript">

    $(document).ready(function () {

        $("#<%=Button1.ClientID %>").click(function () {

            $.ajax({
                type: "GET",
                url: "http://servername.company.happy.com/common/components/userinfo/UserInfoXml.asp?UserID=me",
                dataType: "xml",
                success: function (xml) {
                    $(xml).find('user').each(function () {
                        var phone = $(this).find("telephoneNumber").text();
                        alert(phone);
                    });
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert('Error!'+ textStatus + ' - ' + errorThrown);
                }
            });
        });


    });

</script>

 <h3>Test Test Header</h3>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <h3>Test Test Main</h3>
    </br>
    <asp:Button ID="Button1" runat="server" Text="Submit" />

    </br>
</asp:Content>
10
  • Hey there, which error are you getting up? Commented Jan 9, 2014 at 16:18
  • just a pop up error from AJAX error function that said "ERROR! error - No Transport" Commented Jan 9, 2014 at 16:23
  • 1
    dataType:xml doesn't do anything in this context. I suggest you to add contentType to xml contentType: "text/xml", Commented Jan 9, 2014 at 16:23
  • @PranavRam I removed datatype and still get errorthrown Commented Jan 9, 2014 at 16:25
  • 1
    @MaximilianoRios In my opinion the first two sentences of the question point out that the xml is obtained from a website that the developer does not control. That's why I mentioned the cross domain in my comment. Commented Jan 9, 2014 at 16:50

1 Answer 1

1

I found a simple answer and it really strange. I just need to add $.support.cors = true; above Ajax call to enables cross origin resource sharing. It like subdomain.happy.com is not equal to subdomain2.happy.com

Sign up to request clarification or add additional context in comments.

1 Comment

and I also added contentType: "text/xml". I just vote + your suggested

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.