如何在extjs6中将Ajax发送到远程服务器? [英] How send Ajax to remote server in extjs6?

查看:138
本文介绍了如何在extjs6中将Ajax发送到远程服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在客户端使用Extjs-6.0.0开发应用程序。我在端口80 中运行客户端应用程序。我的服务器端应用程序在 端口8084 中运行。我想创建一个Ajax请求来发送请求到服务器,这个请求的属性如下:





  var json = {
@class:ir.javan.geoad.entity.Melk,
title:itme,
description:Hi all,
callPhone:0912312312,
address:ya ali,
准确度:MANTAQE,
user:{
email:itsme.mm@gmail.com,
name:asdf,
family:asdf
}
};
Ext.Ajax.request({
url:'http:// localhost:8084 / GeoAd / ad / Add',
useDefaultXhrHeader:false,
method:POST ,
cors:true,
headers:{
Content-Type:application / json
},
jsonData:json,
success :function(response){
text = response;
}
});

但这不行。 如何执行

解决方案

由于您的服务器端应用程序位于不同的端口,对它的请求将不起作用,除非您在响应中具有相应的 Access-Control-Allow-Origin 头。这是一个CORS(跨原始资源共享)的东西。



在这里阅读更多信息: http://dev.housetrip.com/2014/04/17/unleash-your-ajax-requests-with- cors /


I'm developing an application using Extjs-6.0.0 in client side. I run client side application in port 80. My server side application running in port 8084. I want to create an Ajax request to send a request to server and this request have attributes as follow:

var json = {
    "@class": "ir.javan.geoad.entity.Melk",
    "title": "itsme",
    "description": "Hi all",
    "callPhone": "0912312312",
    "address": "ya ali",
    "accuracy": "MANTAQE",
    "user": {
        "email": "itsme.mm@gmail.com",
        "name": "asdf",
        "family": "asdf"
    }
};
Ext.Ajax.request({
    url: 'http://localhost:8084/GeoAd/ad/Add',
    useDefaultXhrHeader: false,
    method: "POST",
    cors: true,
    headers: {
        "Content-Type": "application/json"
    },
    jsonData: json,
    success: function(response){
        text = response;
    }
});

But this does not work. How can I do this?

解决方案

Because your server side app is on a different port, AJAX requests to it will not work unless you have a corresponding Access-Control-Allow-Origin header in the response. This is a CORS (cross-origin resource sharing) thing.

Read more about it here: http://dev.housetrip.com/2014/04/17/unleash-your-ajax-requests-with-cors/

这篇关于如何在extjs6中将Ajax发送到远程服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆