locked
Ajax call is not working - Collect Information from merchant transaction page RRS feed

  • Question

  • User917397111 posted

    I am new to Ajax. I want to retrieve the transaction details from the merchant website after payment processing. My ajax call script is not working. Please help.

    C# Method:

    public class RetrieveCache{[WebMethod]public string RetrieveTransactionData(string ID){

    ChannelFactory<ServiceSoap> PayChannelFactory = new ChannelFactory<ServiceSoap>("ServiceSoap12");

    ServiceSoap Paychannel = PayChannelFactory.CreateChannel();

    XmlNode node = Paychannel.RetrieveCachedData(ID);return node.InnerXml;

    }}

    Ajax call Script in HTML Page to call the above c# method

    ​Html Page URL: http://localhost:55014/SuccessPage.html?id=29473740923

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript">

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

    var url = window.location.search; debugger;var token = (url.replace("?", "").split("=")[1]).toString(); debugger;var dataval = JSON.stringify({ token: token }); $.ajax({ url: "http://localhost:55014/RetrieveCache.cs/RetrieveTransactionData", type: 'post', data: JSON.stringify({ token: token }), contentType: 'application/json; charset=utf-8', dataType: 'json', success: function(data){ alert(data);}, error: function (err) { alert(err)}});});

    </script>

    This is the error message in console: localhost:55014/RetrieveCache.cs/RetrieveTransactionData 404 (Not Found)

    Thursday, March 22, 2018 6:18 PM

All replies

  • User475983607 posted

    Is the RetrieveCache an ASMX service as it is missing attributes.

    Remove the .cs from the URL.

    http://localhost:55014/RetrieveCache/RetrieveTransactionData

    Thursday, March 22, 2018 6:26 PM
  • User917397111 posted

    No, it is not an ASMX service. It is just a C# class.

    Is there any way to call a WCF service from HTML page using AJAX? that is my actual requirement... Could you please share a sample if you have any.

    Thank you.

    Thursday, March 22, 2018 6:34 PM
  • User475983607 posted

    No, it is not an ASMX service. It is just a C# class.

    Is there any way to call a WCF service from HTML page using AJAX? that is my actual requirement... Could you please share a sample if you have any.

    Thank you.

    There are literally tons and tons of examples on the web.  However, the posted code and your request is still to vague to guess what you're trying to do.

    ASMX and WCF are natively SOAP services and require configuration to make then REST services which is generally what AJAX expects.  I imagine the merchant has support documentation that you can read that explains the message format.  You'll need that.  

    In the meantime you can learn how to send AJAX requests on the jQuery support page.

    http://api.jquery.com/jquery.ajax/

    And simply Google for examples of using AJAX to invoke a remote service.

    https://www.aspsnippets.com/Articles/ASPNet-MVC-jQuery-AJAX-and-JSON-Example.aspx

    Thursday, March 22, 2018 8:51 PM