kendo mobile json data calling problem

2 posts, 0 answers
  1. Sajid
    Sajid avatar
    6 posts
    Member since:
    Mar 2012

    Posted 16 Apr 2012 Link to this post

    Hi,
     i have written a code for taking json data from a php and putting to listview ,it works great in localhost ,
    when i put the php file in a webserver and called in javascript it showing eeror and not getting data.


    this method i have  used 
     var dataSource = new kendo.data.DataSource({
                    transport: {
                        read: {
                         
                           //url: "userchk.php",    //this works in localhost  
                           url: "http://example.com/web/userchk.php",  this is not working 
                           
                            dataType: "json",
                            data: { 
                                q: "javascript"
                            }
                        }
                    },

    first url data is geting in localhost and works great, second url is not working(but data showing  if we run the url in a browser)

    it show Error

    XMLHttpRequest cannot load http://example.com/web/userchk.php?q=javascript. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

    waiting for a good response
  2. Johan
    Johan avatar
    3 posts
    Member since:
    Dec 2011

    Posted 08 May 2012 Link to this post

    This is due to the basic security restrictions in browsers.
    With JSON you can only use the "only phone home" principle.
    If your JSON service is e.g. http://mysite.com/customers then your mobile app must be on the same domain e.g. http://mysite.com/mymobileapp/index.html.

    See Additional notes on jQuery.ajax()

    Johan
  3. Kendo UI is VS 2017 Ready
Back to Top