This is a migrated thread and some comments may be shown as answers.

Jquery/Zepto $.post does not seem to work...

7 Answers 314 Views
AppBuilder in-browser client
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ryan
Top achievements
Rank 1
Ryan asked on 19 Jun 2012, 06:08 AM
Hey Guys, 
    I'm still trying to get my app to work in Mist (I don't have a Windows machine unfortunately so I think this is my only option), but it seems that $.post calls through jQuery or Zepto fail. I assume it's because the files are not hosted on my server and the aren't running in local mode as compiled apps do so there are security issues. What is the solution for this? Without being able to test my app with $.post calls to my api, it's useless. Am I missing something? I'd love to figure out how to make this work. Conceptually it's a great idea. Thanks

Ryan 

7 Answers, 1 is accepted

Sort by
0
Jordan
Top achievements
Rank 1
answered on 19 Jun 2012, 03:07 PM
Due to browser security restrictions, most "Ajax"
requests are subject to the same origin policy and the request cannot
successfully retrieve data from a different domain, sub-domain, or protocol.
(https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript)

Unfortunately only Graphite (windows client) simulator is applicable for
debugging such scenarios.

But you may workaround this browser limitation by:

1. Test on device as you need to build and install the application only once,
then use [menu] key on Android device or hold down three fingers for 1 sec on
iOS device to sync.

2. Or use CORS and alter security with custom header while testing with Mist simulator
(https://developer.mozilla.org/en/http_access_control)
make your server return this custom header:
   Access-Control-Allow-Origin: http://app.icenium.com

3. Or by using JSONP services
(http://en.wikipedia.org/wiki/JSONP)
Here is an example of JSONP, Twitter search (http://pastebin.com/mD5shPKE) just
paste at index.html in Icenium  new jQuery project.

Please let me know if I can be of any further help,
Jordan
0
Andy
Top achievements
Rank 1
answered on 25 Jul 2012, 11:35 PM
I'm not sure if this will work for you, but I have done this in the past to work around same origin policy problems. When you launch Chrome you can disable security, so the browser won't enforce any of the same origin policy restrictions.

Mac terminal:
open -a Google\ Chrome --args --disable-web-security
0
David
Top achievements
Rank 1
answered on 05 Jun 2013, 03:27 PM
Will this work with Icenium Ion?
0
Steve
Telerik team
answered on 05 Jun 2013, 03:46 PM
Hi David,

ION is just a container for your app, so it would work the same way as your app would work when deployed directly on the device.

Regards,
Steve
Telerik

Looking for tips & tricks directly from the Icenium team? Check out our blog!
Share feedback and vote for features on our Feedback Portal.
0
Abdul
Top achievements
Rank 1
answered on 20 Jun 2013, 07:26 AM
Hi Steve,
                 How r u...
while connecting REST i am getting error....
Error:
Origin http://app.icenium.com is not allowed by Access-Control-Allow-Origin.

Code :

function getContactList(){
          
        console.log("Entering getContactList()");
          
        $.ajax({
             
            type: "GET",
            url : "http://localhost:8080/rest/3.2/contactinfo/contactrest",
            dataType: "xml",
             cache: true,
            
            
          error:function (xhr, ajaxOptions, thrownError){
            debugger;
                    alert(xhr.statusText);
                    alert(thrownError);
                },
            
          success : function(xml) {
            console.log("Entering getContactList.success()");
          
            $(xml).find("contactrest").each(function()
            {
              var html = '<li>' + $(this).find("fname").text()
              + ' ' + $(this).find("lname").text() +'</li>';
              $('#emp').append(html);
            });
            console.log("Exiting getContactList.success()");
          }
        });
        console.log("Exiting getContactList()");
          
          
      }

thanks and regards
muthalif



0
Chris Gillies
Top achievements
Rank 1
answered on 20 Jun 2013, 07:52 AM
XMLHttpRequest will not let you reach localhost because of the "same origin policy".This error has been discussed times and times again, just search for "is not allowed by Access-Control-Allow-Origin", here are a few posts with nice explanations:
  • http://www.cypressnorth.com/blog/programming/cross-domain-ajax-request-with-json-response-for-iefirefoxchrome-safari-jquery/
  • http://stackoverflow.com/questions/10143093/origin-is-not-allowed-by-access-control-allow-origin
0
Iva Koevska
Telerik team
answered on 17 Apr 2014, 03:02 PM
Hi all,

If you're using the in-browser client in Chrome, you can get the Telerik AppBuilder Helper for Chrome which enables Ajax CORS requests for the device simulator to spare you the CORS errors.

You can get it from here. The team plans to bring more improvements in the Helper in the future, so keep an eye on it.

Regards,
Iva Koevska
Telerik
 

Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!

 
Tags
AppBuilder in-browser client
Asked by
Ryan
Top achievements
Rank 1
Answers by
Jordan
Top achievements
Rank 1
Andy
Top achievements
Rank 1
David
Top achievements
Rank 1
Steve
Telerik team
Abdul
Top achievements
Rank 1
Chris Gillies
Top achievements
Rank 1
Iva Koevska
Telerik team
Share this question
or