wcf, asp.net, jquery /ajax restful

Below code working in IE but not Chrome.  And I verified the service actually went thought to the browser.
I believe something wrong when it is passing the parameters like below

url: GetSaleTax + encodeURIComponent("(066,''," + city + "," + state + "," + zip + ",USA)"),

But I do not know how to fix it. I also have another service call and it is working but that one does not need to pass parameters.

Second Question is: I want pass SalesTaxRate to input text box "taxRate". Please help.

return error:
XMLHttpRequest cannot load http://clientaccesstest.abc.com/wcf/orders/RestService/ProQuoteServiceJVC/GetSaleTax(066%2C''%2CCOLUMBUS%2CIN%2C47201%2CUSA)?_=1428433379116. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:62937' is therefore not allowed access.

export result after service is called:

<Status>Completed</Status><CustomerNumber></CustomerNumber><ShipToCity>COLUMBUS</ShipToCity><ShipToState>IN</ShipToState><ShipToZip>47201</ShipToZip><ShipToCountry>USA</ShipToCountry><SalesTaxRate>7.000</SalesTaxRate>

Script:

<script type="text/javascript">
    function GetSaleTaxList(city, state, zip) {

        city = "COLUMBUS";
        state = "IN";
        zip = "47201";

        var GetSaleTax = "http://clientaccesstest.abc.com/wcf/orders/RestService/ProQuoteServiceJVC/GetSaleTax";            
            if (city == '' || state == '' || zip == '' ) {
                  //setSaleTaxInfo("NO RATE");
            }else if (state == 'XX') {
                  //setSaleTaxInfo("NO RATE");
            }else{
                  $(document).ready(function () {
                              
                        //alert(GetSaleTax);
                        $.ajax({
                              cache: false,
                              type: "GET",
                              async: false,
                              dataType: "json",
                              contentType: 'text/plain',
                              url: GetSaleTax + encodeURIComponent("(066,''," + city + "," + state + "," + zip + ",USA)"),
                              success: function (data) {
                                    $('#data').html(data);
                                    alert(data + " : data");
                                    if (data == null)
                                          return;
                                    //setSaleTaxInfo(data);
                                    //resultObj = jQuery.parseJSON(data);
                                    //if (resultObj.Status != 'Failed') {
                                    //    $('#json').html(setSaleTaxInfo(resultObj.Data));
                                    //}
                              },
                              error: function (xhr) {
                                    //$('#data').html(xhr.responseText);
                                    alert(xhr.responseText + " : error GetSaleTax");

                              }
                        });
                  });
            }
}
</script>

<input type="text" name="taxRate" id="taxRate">
LVL 1
ITsolutionWizardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ambienceCommented:
This part looks suspicious

"(066,''," + city

shouldnt it be

"(066,'' + city
0
ITsolutionWizardAuthor Commented:
even I use "(066,'' + city  same issue
0
CtrlAltDlCommented:
I see a couple potential problems.

1. You are registering your jQuery $(document).ready() event within your GetSaleTaxList() function.  There are some unlikely reasons to do this, but I don't think this is your intention here.

2. encodeURIComponent() returns a url encoded string, and it requires one string as a parameter.  You have 5 comma delimited parameters. The first parameter is "(066,", the second parameter is " + city + ", etc...

I think this should be closer to what you are expecting:
<script type="text/javascript">
$(document).ready(function () {
    function GetSaleTaxList(city, state, zip) {

        city = "COLUMBUS";
        state = "IN";
        zip = "47201";

        var GetSaleTax = "http://clientaccesstest.abc.com/wcf/orders/RestService/ProQuoteServiceJVC/GetSaleTax";            
            if (city == '' || state == '' || zip == '' ) {
                  //setSaleTaxInfo("NO RATE");
            }else if (state == 'XX') {
                  //setSaleTaxInfo("NO RATE");
            }else{
                        //alert(GetSaleTax);
                        $.ajax({
                              cache: false,
                              type: "GET",
                              async: false,
                              dataType: "json",
                              contentType: 'text/plain',
                              url: GetSaleTax + encodeURIComponent("(066," + city + "," + state + "," + zip + ",USA)"),
                              success: function (data) {
                                    $('#data').html(data);
                                    alert(data + " : data");
                                    if (data == null)
                                          return;
                                    //setSaleTaxInfo(data);
                                    //resultObj = jQuery.parseJSON(data);
                                    //if (resultObj.Status != 'Failed') {
                                    //    $('#json').html(setSaleTaxInfo(resultObj.Data));
                                    //}
                              },
                              error: function (xhr) {
                                    //$('#data').html(xhr.responseText);
                                    alert(xhr.responseText + " : error GetSaleTax");

                              }
                  });
            }
     }
});
</script>

<input type="text" name="taxRate" id="taxRate">

Open in new window

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

ITsolutionWizardAuthor Commented:
Let me repost the codes. I may copied something wrong in the past. sorry.
Overall, below is correct codes, and even I use your way to call. It still returns error. See attached.
Also, the screenshot show red on right, and may be that is the cause. not sure.

<script type="text/javascript">
    function GetSaleTaxList() {
        var city = "COLUMBUS";
        var state = "IN";
        var zip = "47201";
        var str = "(066,337557,COLUMBUS,IN,47201,USA)";
        var GetSaleTax = "http://clientaccesstest.abc.com/wcf/orders/RestService/QuoteService/GetSaleTax";
        if (city == '' || state == '' || zip == '') {
            //setSaleTaxInfo("NO RATE");
        } else if (state == 'XX') {
            //setSaleTaxInfo("NO RATE");
        } else {
            $(document).ready(function () {
                //alert(GetSaleTax);
                $.ajax({
                    cache: false,
                    type: "GET",
                    async: false,
                    dataType: "json",
                    contentType: 'text/plain',
                    url: GetSaleTax + encodeURIComponent("(066,337557," + city + "," + state + "," + zip + ",USA)"),
                    processData: true,
                    // [WebGet(UriTemplate = "ProQuoteServiceJVC/GetSaleTax({CompanyID},{CustomerNo},{ShipToCity},{ShipToState},{ShipToZip},{ShipToCountry})")]

                    success: function (data) {
                        alert(data + " : data");
                        if (data == null)
                            return;                        
                    },
                    error: function (xhr) {
                        //$('#data').html(xhr.responseText);
                        alert(xhr.responseText + " : error GetSaleTax");

                    }
                });
            });
        }
    }
</script>
error8.jpg
0
ITsolutionWizardAuthor Commented:
don't worry about the service name. I re-name for security purpose.
0
ambienceCommented:
Can you check the output in Firebug and post it here? There must be some errors in the console tab
0
ITsolutionWizardAuthor Commented:
yes. please view attachment.
error8.jpg
0
ambienceCommented:
This looks an error in the returned JSON data. Can you also paste the raw returned JSON? Also, the contents of the Console tab?
0
ITsolutionWizardAuthor Commented:
how can I do that in chrome?
0
ITsolutionWizardAuthor Commented:
I guess you want raw response. see attached. one from chrome, one from IE.
error8a.jpg
error8b.jpg
0
ITsolutionWizardAuthor Commented:
I also have another wcf call in jquery and return below result. I copy and paste from Chrome.

And still this call has same error as the one posted.

<Status>Completed</Status><CustomerNumber>335281</CustomerNumber><OrderDate>04-08-15</OrderDate><OrderDetail><Item id="0"><Model><![CDATA[AAS3602I]]></Model><Quantity>1</Quantity><DealerPrice>226.000</DealerPrice><NetPrice>226.000</NetPrice></Item></OrderDetail>
0
ITsolutionWizardAuthor Commented:
ignore my last post.
0
ITsolutionWizardAuthor Commented:
so any ideas?
0
CtrlAltDlCommented:
Either that isn't your "raw" JSON or your GetSaleTax web service is returning XML and not JSON.  I would need to see the code of your web service to help further.  Does this web service work for any other applications?

Or I can show you how to parse that data as XML not JSON.
0
ITsolutionWizardAuthor Commented:
the web service return as string, and string will be xml format.
Yes, you can show me how to pars the data as xml not json.

As long as this error is not occurred. It is good to go.

Question: so regardless of which datatype will be response, if assume the web service response datatype as xml,
and in jquery code I code for json datatype, it is still generated an error as cross domain issue?
0
ITsolutionWizardAuthor Commented:
Below is web service (wcf) codes if you want to read.

#region GetSaleTax
        public string GetSaleTax(string CompanyID, string CustomerNo, string ShipToCity, string ShipToState, string ShipToZip, string ShipToCountry)
        {
            #region procedures
            try
            {
            string body = string.Format(@"<SOAP:Envelope><SOAP:Header></SOAP:Header>
            <SOAP:Body>
            <m:Retrieve>
            <itemid>
            <GenerateReportRequest>
            <ReportType>CUST-SALESTAX</ReportType>
            <ReportFormat>XML</ReportFormat>
            <ReportParams>
            <CompanyNumber>{0}</CompanyNumber>
            <CustomerNumber>{1}</CustomerNumber>
            <ShipToCity>{2}</ShipToCity>
            <ShipToState>{3}</ShipToState>
            <ShipToZip>{4}</ShipToZip>
            <ShipToCountry>{5}</ShipToCountry>
            </ReportParams>
            </GenerateReportRequest>
            </itemid>
            </m:Retrieve>
            </SOAP:Body>
            </SOAP:Envelope>", CompanyID, CustomerNo,ShipToCity,ShipToState,ShipToZip,ShipToCountry);
                abc.B2B.ERP.jBase.Helper.Retrieve d = new Kenwood.B2B.ERP.jBase.Helper.Retrieve(body);
                XmlDocument xml = new XmlDocument();
                xml.LoadXml(d.GetData());
                string node = xml.SelectSingleNode("//RetrieveResult").InnerXml;
                return node;
            }
            catch (Exception ex)
            {
                //ILog log = LogManager.GetLogger("");
                //log.Error(m => m("Error:", ex.ToString()));
                throw ex;
            }
            #endregion
        }
        #endregion
0
ITsolutionWizardAuthor Commented:
here is the interface

 #region GetSaleTax
        [OperationContract]
        [WebGet(UriTemplate = "ProQuoteServiceJVC/GetSaleTax({CompanyID},{CustomerNo},{ShipToCity},{ShipToState},{ShipToZip},{ShipToCountry})")]
        String GetSaleTax(string CompanyID, string CustomerNo, string ShipToCity, string ShipToState, string ShipToZip, string ShipToCountry);
        #endregion
0
ITsolutionWizardAuthor Commented:
ignore previous one. look below one

 #region GetSaleTax
        [OperationContract]
        [WebGet(UriTemplate = "QuoteService/GetSaleTax({CompanyID},{CustomerNo},{ShipToCity},{ShipToState},{ShipToZip},{ShipToCountry})")]
        String GetSaleTax(string CompanyID, string CustomerNo, string ShipToCity, string ShipToState, string ShipToZip, string ShipToCountry);
        #endregion
0
ITsolutionWizardAuthor Commented:
any updates?
0
ambienceCommented:
Your webservice is SOAP based and therefore it is much easier and better to use a SOAP client rather than raw AJAX and parse XML (though that is a possibility).

Consider using this jQuery plugin: https://github.com/doedje/jquery.soap
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ITsolutionWizardAuthor Commented:
can you show me in codes? I do not know much about the plug in you mentioned.

or

you can show me how to make the existing web service converting to json based.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WCF

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.