ITsolutionWizard
asked on
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-Orig in' 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> <CustomerN umber></Cu stomerNumb er><ShipTo City>COLUM BUS</ShipT oCity><Shi pToState>I N</ShipToS tate><Ship ToZip>4720 1</ShipToZ ip><ShipTo Country>US A</ShipToC ountry><Sa lesTaxRate >7.000</Sa lesTaxRate >
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(setSaleTax Info(resul tObj.Data) );
//}
},
error: function (xhr) {
//$('#data').html(xhr.resp onseText);
alert(xhr.responseText + " : error GetSaleTax");
}
});
});
}
}
</script>
<input type="text" name="taxRate" id="taxRate">
I believe something wrong when it is passing the parameters like below
url: GetSaleTax + encodeURIComponent("(066,'
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-Orig
export result after service is called:
<Status>Completed</Status>
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,'
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(setSaleTax
//}
},
error: function (xhr) {
//$('#data').html(xhr.resp
alert(xhr.responseText + " : error GetSaleTax");
}
});
});
}
}
</script>
<input type="text" name="taxRate" id="taxRate">
ASKER
even I use "(066,'' + city same issue
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:
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">
ASKER
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,4 7201,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,3 37557," + city + "," + state + "," + zip + ",USA)"),
processData: true,
// [WebGet(UriTemplate = "ProQuoteServiceJVC/GetSal eTax({Comp anyID},{Cu stomerNo}, {ShipToCit y},{ShipTo State},{Sh ipToZip},{ ShipToCoun try})")]
success: function (data) {
alert(data + " : data");
if (data == null)
return;
},
error: function (xhr) {
//$('#data').html(xhr.resp onseText);
alert(xhr.responseText + " : error GetSaleTax");
}
});
});
}
}
</script>
error8.jpg
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,4
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,3
processData: true,
// [WebGet(UriTemplate = "ProQuoteServiceJVC/GetSal
success: function (data) {
alert(data + " : data");
if (data == null)
return;
},
error: function (xhr) {
//$('#data').html(xhr.resp
alert(xhr.responseText + " : error GetSaleTax");
}
});
});
}
}
</script>
error8.jpg
ASKER
don't worry about the service name. I re-name for security purpose.
Can you check the output in Firebug and post it here? There must be some errors in the console tab
ASKER
yes. please view attachment.
error8.jpg
error8.jpg
This looks an error in the returned JSON data. Can you also paste the raw returned JSON? Also, the contents of the Console tab?
ASKER
how can I do that in chrome?
ASKER
ASKER
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> <CustomerN umber>3352 81</Custom erNumber>< OrderDate> 04-08-15</ OrderDate> <OrderDeta il><Item id="0"><Model><![CDATA[AAS 3602I]]></ Model><Qua ntity>1</Q uantity><D ealerPrice >226.000</ DealerPric e><NetPric e>226.000< /NetPrice> </Item></O rderDetail >
And still this call has same error as the one posted.
<Status>Completed</Status>
ASKER
ignore my last post.
ASKER
so any ideas?
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.
Or I can show you how to parse that data as XML not JSON.
ASKER
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?
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?
ASKER
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:Enve lope><SOAP :Header></ SOAP:Heade r>
<SOAP:Body>
<m:Retrieve>
<itemid>
<GenerateReportRequest>
<ReportType>CUST-SALESTAX< /ReportTyp e>
<ReportFormat>XML</ReportF ormat>
<ReportParams>
<CompanyNumber>{0}</Compan yNumber>
<CustomerNumber>{1}</Custo merNumber>
<ShipToCity>{2}</ShipToCit y>
<ShipToState>{3}</ShipToSt ate>
<ShipToZip>{4}</ShipToZip>
<ShipToCountry>{5}</ShipTo Country>
</ReportParams>
</GenerateReportRequest>
</itemid>
</m:Retrieve>
</SOAP:Body>
</SOAP:Envelope>", CompanyID, CustomerNo,ShipToCity,Ship ToState,Sh ipToZip,Sh ipToCountr y);
abc.B2B.ERP.jBase.Helper.R etrieve d = new Kenwood.B2B.ERP.jBase.Help er.Retriev e(body);
XmlDocument xml = new XmlDocument();
xml.LoadXml(d.GetData());
string node = xml.SelectSingleNode("//Re trieveResu lt").Inner Xml;
return node;
}
catch (Exception ex)
{
//ILog log = LogManager.GetLogger("");
//log.Error(m => m("Error:", ex.ToString()));
throw ex;
}
#endregion
}
#endregion
#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:Enve
<SOAP:Body>
<m:Retrieve>
<itemid>
<GenerateReportRequest>
<ReportType>CUST-SALESTAX<
<ReportFormat>XML</ReportF
<ReportParams>
<CompanyNumber>{0}</Compan
<CustomerNumber>{1}</Custo
<ShipToCity>{2}</ShipToCit
<ShipToState>{3}</ShipToSt
<ShipToZip>{4}</ShipToZip>
<ShipToCountry>{5}</ShipTo
</ReportParams>
</GenerateReportRequest>
</itemid>
</m:Retrieve>
</SOAP:Body>
</SOAP:Envelope>", CompanyID, CustomerNo,ShipToCity,Ship
abc.B2B.ERP.jBase.Helper.R
XmlDocument xml = new XmlDocument();
xml.LoadXml(d.GetData());
string node = xml.SelectSingleNode("//Re
return node;
}
catch (Exception ex)
{
//ILog log = LogManager.GetLogger("");
//log.Error(m => m("Error:", ex.ToString()));
throw ex;
}
#endregion
}
#endregion
ASKER
here is the interface
#region GetSaleTax
[OperationContract]
[WebGet(UriTemplate = "ProQuoteServiceJVC/GetSal eTax({Comp anyID},{Cu stomerNo}, {ShipToCit y},{ShipTo State},{Sh ipToZip},{ ShipToCoun try})")]
String GetSaleTax(string CompanyID, string CustomerNo, string ShipToCity, string ShipToState, string ShipToZip, string ShipToCountry);
#endregion
#region GetSaleTax
[OperationContract]
[WebGet(UriTemplate = "ProQuoteServiceJVC/GetSal
String GetSaleTax(string CompanyID, string CustomerNo, string ShipToCity, string ShipToState, string ShipToZip, string ShipToCountry);
#endregion
ASKER
ignore previous one. look below one
#region GetSaleTax
[OperationContract]
[WebGet(UriTemplate = "QuoteService/GetSaleTax({ CompanyID} ,{Customer No},{ShipT oCity},{Sh ipToState} ,{ShipToZi p},{ShipTo Country})" )]
String GetSaleTax(string CompanyID, string CustomerNo, string ShipToCity, string ShipToState, string ShipToZip, string ShipToCountry);
#endregion
#region GetSaleTax
[OperationContract]
[WebGet(UriTemplate = "QuoteService/GetSaleTax({
String GetSaleTax(string CompanyID, string CustomerNo, string ShipToCity, string ShipToState, string ShipToZip, string ShipToCountry);
#endregion
ASKER
any updates?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
or
you can show me how to make the existing web service converting to json based.
"(066,''," + city
shouldnt it be
"(066,'' + city