0

OK so my asp.net MVC4 controller called Home is almost restful, so if I do this in Firefox or IE

http://localhost:1193/Home/?serialcode=123456789123321

It gracefully shows a page with a code like 82434234 calculated using the serialcode above.

Now the controller supports returning XML data, tested and works with C# code. Now I'm stuck at the final step...ehm...sending a simple ajax request to get the code. This is what i have so far

                var xmlHttp;

                **//Problem 1: not sure what url should be like, given above Firefox
                // example ? Should the word Home , or index be in it?**

                var url = "index?serialcode=123456789123321";                    

                if (window.XMLHttpRequest) {
                    // code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                }
                else {
                    // code for IE6, IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xml.dataType = "xml";

                **// Problem 2: this line doesn't do anything below**
                xmlHttp.open("GET", url , true);             

                xmlHttp.send(imei);

Any help GREATLY appreciated...thanks :)

2 Answers 2

1

Simplify things and use jQuery:

$.ajax({
  url: '@Url.Action("Index", "Home")',
  type: 'GET',
  data: { serialcode: 123456789123321 },
  success: function(responseData) {
    // TODO:
  }
});
Sign up to request clarification or add additional context in comments.

1 Comment

after adding dataType: 'xml' to it, now i am getting an XML document back...Super!! I can use that.Thxxx
0

Use Url.Action() to get the URL. Pass the data by replacing your above code with a simple jQuery.ajax() call.

Comments

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.