Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

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);
                }
            });
        });
}
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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

Avatar of ITsolutionWizard

ASKER

tried already. same issue is still occurred.
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.
Q1: I do not have to use encodeURLComponent.
Q2: the client is html with jquery call. Not MVC.
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial