“No 'Access-Control-Allow-Origin' header is present on the requested resource

2 posts, 0 answers
  1. Imran
    Imran avatar
    8 posts
    Member since:
    Oct 2013

    Posted 06 Jan Link to this post

    Hi,

    I am working on hybrid application and I have created login page and I am passing params username & password to api,

    but ia mgetting following error:

    “No 'Access-Control-Allow-Origin' header is present on the requested resource.

    I found solution for that from stackoverflow

    http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource

    but still I am not able to data

    my code is as follow:

    <div data-role="view" data-title="Home View" data-layout="main" data-model="app.home" data-show="app.home.onShow" data-after-show="app.home.afterShow">
        <div class="signin-view">
            <form>
                <ul data-role="listview" data-style="inset">
                    <li>
                        <label>Email
                            <input type="email" id="email" data-bind="value: homeModel.email" required autofocus>
                        </label>
                    </li>
                    <li>
                        <label>Password
                            <input type="password" id="password" data-bind="value: homeModel.password" required>
                        </label>
                    </li>
                </ul>
                <div class="button-group button-group-vertical">
                    <a data-role="button" class="primary" data-bind="events: { click: homeModel.signin }">Sign In</a>
                    <a data-role="button" data-bind="events: { click: homeModel.toggleView }">Register</a>
                    <a class="primary" data-role="button" id="btnlogin">click</a>
                </div>
            </form>
        </div>
        <div class="signup-view" style="display:none;">
            <form>
                <ul data-role="listview" data-style="inset">
                    <li>
                        <label>Email
                            <input type="email" data-bind="value: homeModel.email" required>
                        </label>
                    </li>
                    <li>
                        <label>Password
                            <input type="password" data-bind="value: homeModel.password">
                        </label>
                    </li>
                    <li>
                        <label>Name
                            <input type="text" data-bind="value: homeModel.displayName">
                        </label>
                    </li>
                </ul>
                <div class="button-group button-group-vertical">
                    <a class="primary" data-role="button" data-bind="events: { click: homeModel.register }">Register</a>
                    <a data-role="button" data-bind="events: { click: homeModel.toggleView }">Sign In</a>
                </div>
            </form>
        </div>
        <div class="offline" align="center" style="display:none;">
            You are currently offline. Before using this app in offline mode you must initialize it while you are online
        </div>
        <!-- START_CUSTOM_CODE_homeModel -->
        <!-- Add custom code here. For more information about custom code, see http://docs.telerik.com/platform/screenbuilder/troubleshooting/how-to-keep-custom-code-changes -->
        <!-- END_CUSTOM_CODE_homeModel -->
        <!-- START_CUSTOM_CODE_home -->
        <!-- Add custom code here. For more information about custom code, see http://docs.telerik.com/platform/screenbuilder/troubleshooting/how-to-keep-custom-code-changes -->
        <!-- END_CUSTOM_CODE_home -->
        <script type="text/javascript">
            $('#btnlogin').click(function () {
                        var username = $('#email').val();
                        var password = $('#password').val();
                        alert(username + "," + password);
                        $.ajax({
                                url: "http://www.mivbvpn.com:8040/api/users?",
                                data: {
                                    Username: username,
                                    Password: password
                                },
                                type: "get",
                                dataType: "jsonp",                       
                                success: function (result) {
                                    alert(result.FullName);
                                },
                                error: function (xhr, result) {
                                    alert(xhr.status);
                                }
                                });
                        });
        </script>
    </div>

     

    when I run application I am getting status 200 as screen attached.

    please help me to solve this issue.

    thank you

  2. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 08 Jan Link to this post

    Hi Imran,

    Can you confirm that you have set your server to accept requests from other domains? Unless you have allowed access from other locations, you won't be able to read data in your app from this service.

    If this web service works with remote requests, you can try running your app in the Simulator in the AppBuilder Windows client or directly on a device.

    Regards,
    Tsvetina
    Telerik
     

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

     
Back to Top