[RESOLVED]Data get written out on page after jquery ajax call to method

I’m calling a method and passing an id to get a product in the form of xml. It’s working fine but i’m writing out the results to the page which I don’t want. I would like to work with the xml on the ajax success. Is there a better way of doing this?

Method located in: Methods/getProduct.cshtml

        var itemID = Request["itemID"];

        string MY_AWS_ACCESS_KEY_ID = "00";
        string MY_AWS_SECRET_KEY = "00";
        string DESTINATION = "ecs.amazonaws.com";
        string ASSOCIATE_TAG = "0000-20";
        string NAMESPACE = "http://webservices.amazon.com/AWSECommerceService/2013-08-01";

        var helper = new AmazonProductAdvtApi.SignedRequestHelper(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY, DESTINATION);
        var r1 = new Dictionary<string, String>();
        r1["Service"] = "AWSECommerceService";
        r1["Version"] = "2013-08-01";
        r1["Operation"] = "ItemLookup";
        r1["ItemId"] = itemID;
        r1["ResponseGroup"] = "Medium";
        r1["AssociateTag"] = ASSOCIATE_TAG;

        // Get the signed url
        var requestUrl = helper.Sign(r1);

        // Make the request
        var client = new WebClient();
        var xml = client.DownloadString(requestUrl);


    else {

Jquery located in Product.cshtml

<script type="text/javascript">
    $(function () {

        $("#formGetProduct").submit(function (e) {

        function request() {
                type: "POST",
                url: "Methods/getProduct",
                data: "itemID=" + $("#productId").val(),
                success: function (data) {


You could probably do with reading this first: https://www.udemy.com/blog/jquery-xml/

Two points: you should make sure the Response.ContentType in your getProduct file is set to application/xml, and you should use GET in your jquery instead of POST.

Leave a Reply