jquery, encodeurlcomponent

Below jquery ajax is working fine. What I want to do is below:
url: GetModelListJSon + encodeURIComponent("(011,115217)"),

I want to be
var customerNo = "111";
var companyNo = "222";
and I got error alert in Chrome saying below:

XMLHttpRequest cannot load http://clientaccesstest.abc.com/wcf/orders/RestService/QuoteServiceJVC/GeModelList(.....)?_=1428433644469. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:62937' is therefore not allowed access.

The web service is working fine without cross domain issue. When I hard code like below, it works fine. Any ideas how to fix it?


url: GetModelListJSon + encodeURIComponent("(customerNo,companyNo)"),



function GetModelList(divisCode)
      var customerNo = "315217";            
        var GetModelListJSon = "http://clientaccesstest.abc/GetModel";            
        $(document).ready(function () {
            $.ajax({
              crossDomain: true,
                cache: false,
                type: "GET",
                async: false,
                dataType: "json",
                contentType: 'text/plain',
                url: GetModelListJSon + encodeURIComponent("(011,115217)"),
                success: function (data) {
                    $('#data').html(data);
                    if (data == null)
                        return;
                    resultObj = jQuery.parseJSON(data);
                    if (resultObj.Status != 'Failed') {
                        $('#json').html(setModelInfo(resultObj.Data,divisCode));
                    }
                },
                error: function (xhr,status,error) {
                    $('#data').html(xhr.responseText);
                    alert(xhr.responseText + " : error GetModelListJSon");
alert(status);
alert(error);
                }
            });
        });
}
LVL 1
ITsolutionWizardAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Miguel OzSoftware EngineerCommented:
You need to send value of your variables, please replace:
url: GetModelListJSon + encodeURIComponent("(customerNo,companyNo)"),

Open in new window

with:
url: GetModelListJSon + encodeURIComponent("(" + customerNo +"," + companyNo+")"),

Open in new window

ITsolutionWizardAuthor Commented:
tried already. same issue is still occurred.
Miguel OzSoftware EngineerCommented:
Is this value correct? var GetModelListJSon = "http://clientaccesstest.abc/GetModel";    
If you test:
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Variables</h1>
<p id="demo"></p>
<script>
var customerNo = "111";
var companyNo = "222";
var z = "(" + customerNo +"," + companyNo+")";
document.getElementById("demo").innerHTML = encodeURIComponent(z);
</script>
</body>
</html>

Open in new window

is returning the correct string. Your error states GetModelList not GetModel (unless you are using MVC routing)

Questions:
Q1. Any particular reason you are using encodeURIComponent?
Q2. If you are using ASP.NET MVC can you post your action signature as well as the associated mapping?
In MVC we usually pass parameters as "api/{controller}/{par1}/{par2}" as shown here.
ITsolutionWizardAuthor Commented:
Q1: I do not have to use encodeURLComponent.
Q2: the client is html with jquery call. Not MVC.
Miguel OzSoftware EngineerCommented:
Just to clarify
Q3. Is the jquery call to a web method with two parameters?
Q4. What kind of web service is this method implemented? If it is WCF can you post the method declaration including the attributes you use to set it up and any relevant configuration settings.
For web services we typically use the data property to pass the parameters not the Url property as shown here.

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
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
JavaScript

From novice to tech pro — start learning today.