1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    1
    Vote Rating
    0
    unocuatro is on a distinguished road

      0  

    Default Unanswered: request a cross-domain

    Unanswered: request a cross-domain


    Hi, i need help, i am just doing a simple app with a button to request, and only want to connect my app with server's aplication, i only want to connect NO MORE!.
    here is my code.
    this is my controller and into it im doing everything...
    MainController.js
    Code:
    Ext.define("MyApp.controller.MainController", {
    	    extend: "Ext.app.Controller",
                requires:['Ext.data.JsonP'],
                
               config:{
                    refs:{
                        boton:'#botonR',
                        showRequest:'#showRequest'                    
                        },
                    control:{
                        boton:{
                            tap: 'doRequest'                        
                        }                    
                    }                        
               },
        
               
               doRequest: function(){                                        
                     
         
                      
                       Ext.Ajax.request({
                            url:'http://wap.lucky-club.com/cgi-bin/plasma/senchaTest.py', // this is the domain
                            method:'POST',
                            params:{ hola:'hola'},
                            scriptTag: true,
                            success: function(response,options){
                                        console.debug('success');
                                       // var result = Ext.JSON.decode(response.responseText);                                    
                                        this.getShowRequest().setHtml(response.responseText);
                                        console.debug(result);
                                        
                            },
                            failure: function(response,options){
                                        console.debug('fail');
                                      //  var result = Ext.JSON.decode(response.responseText);                                   
                                        this.getShowRequest().setHtml('fallo');
                                         console.debug(response);
                            },
                            scope:this
                            
                            
                            });
    
    
                    
               }
               
        });
    Server side: senchaTest.py

    Code:
    #! /usr/bin/python# -*- coding: utf-8 -*-
    
    
    import json
    
    
    
    
    res = {"success": "true", "response": "OK" }
    
    
    print 'content-type:text/javascript'
    print
    print json.dumps(res)
    Can someone help me?
    THANK U SO MUCH! I hope someone can help me is urgent! X_x

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    872
    Answers
    3564
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Your server or server-side code needs to support CORS which is just sending headers back.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Location
    Poland
    Posts
    70
    Vote Rating
    5
    Answers
    4
    szimek is on a distinguished road

      0  

    Default


    If it's just for your own testing purposes, then you can start Chrome browser with --disable-web-security switch to disable cross domain check - this way Ajax requests will work even if domain/port doesn't match.

    If you want others to use this app as well, then like Mitchell said, you'll need to add CORS support to your server app, which is pretty easy.