RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-313160

lzhec's questions

Martin Hope
lzhec
Asked: 2020-02-18 15:41:02 +0000 UTC

如何将ajax POST传递到本地服务器

  • 0

有一个django项目,apache2服务器,Ubuntu18.04系统,在js项目中有一个脚本,需要从该脚本向本地服务器上的一个php脚本发送POST请求。在 /etc/hosts 中将域 myserver.com 分配给 IP 127.0.0.1,在 Apache 中配置 /web 根文件夹。但是尝试向服务器发送请求会导致错误

POST http://myserver.com/script/ net::ERR_NAME_NOT_RESOLVED

如果你放的是localhost地址而不是域,那么就不会出现这个错误,但是会出现CORS错误:

POST http://localhost/script/ 404 (Not Found)
Access to XMLHttpRequest at 'http://localhost/script/' from origin 'http://site.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

但是在具有相同设置的 Windows 计算机上,一切正常。

脚本.js:

sendMail: function (formid) {
        var formId = "#" + formid;
        var fd = new FormData(document.querySelector(formId));
        var url = 'http://myserver.com/script/';
        $.ajax({
            url: url,
            type: "POST",
            data: fd,
            cache: true,
            processData: false,
            contentType: false,
            beforeSend: function () {
...

索引.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>myserver</title>
</head>
<body>
  <h2>myserver</h2>
  <?php
    header("Access-Control-Allow-Origin: *");
    header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS");
    header("Access-Control-Allow-Headers: *");
    require_once 'script.php';
  ?>
</body>
</html>
javascript
  • 2 个回答
  • 10 Views
Martin Hope
lzhec
Asked: 2020-01-31 21:04:19 +0000 UTC

django 在生产服务器上看不到模板

  • 0

美好的一天!

遇到这样的问题。在生产服务器上加载站点时,Linux Django 开始发誓缺少模板:TemplateDoesNotExist at /home main/index.html。

web/site.ru/mainApp/views.py in home return render(request, 'main/index.html', {'form':form}, locals())

尽管一切都在本地服务器上运行。我怀疑这是由于 Windows 和 Linux 上的相对路径不同(该项目是在本地 Windows 机器上开发的)

设置.py

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join('templates')],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },
},

]

TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)

视图.py

def home(request):
form = RequestForm(request.POST or None)

if request.method == 'POST' and form.is_valid():
    new_form = form.save()
    messages.success(request, 'Ваш запрос успешно отправлен')
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

return render(request, 'main/index.html', {'form':form}, locals())
python
  • 1 个回答
  • 10 Views
Martin Hope
lzhec
Asked: 2020-01-27 00:29:24 +0000 UTC

将 POST 从应用程序发送到服务器

  • -1

美好的一天。

django上有一个应用,连接了js和php编写的第三方插件。其本质是用户填写表单,点击“发送”,我收到一封包含用户申诉的邮件。问题是python服务器不处理php,所以我连接了apache并将其指向一个目录,其中包含实现该功能的php脚本。所以,我不能以任何方式向服务器发送跨域请求。如果我使用 jsonp,那么浏览器会发誓 MIME 类型 text/html: jsonp

如果我使用标头,我会收到错误响应预检请求: 访问控制允许来源

我不擅长CORS,但据我了解,错误发生在飞行前请求上,即应用程序和服务器在发送数据之前交换标头。如何编写 CORS 以使验证成功?

ajax
  • 2 个回答
  • 10 Views
Martin Hope
lzhec
Asked: 2020-12-14 16:55:32 +0000 UTC

一个组件中有两个指令。冲突

  • 0

大家下午好!

我的任务是在一个组件中加载两个外部模块。我通过渲染指令加载外部脚本。问题是只加载了最后一个,加载时第一个被“覆盖”。当我创建一个新元素时,我发现这都是关于渲染的。如何解决?

home.component.html

<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="nav-home-tab">
  <searchTourSimple [script]="'src/app/scripts/homeSearch.js'"></searchTourSimple>
</div>
<div class="shop-window">
  <div id="shopwindow-container">
    <shopWindow [script]="'src/app/scripts/shopwindow.js'"></shopWindow>
  </div>
</div>

dir1.directive.ts

@Directive({
  selector: 'searchTourSimple'
})

export class SearchModuleSimpleDirective implements OnInit {
  @Input('script') param: any
  script: any

  constructor(private renderer:Renderer2) { }

  ngOnInit() {

    this.script = this.renderer.createElement('script')     
    this.script.type = 'text/javascript'    
    this.script.src = this.param
    this.script.async = true
    this.renderer.appendChild(document.head, this.script)

    document.write = function(input: string) {
      document.getElementById('home').innerHTML += input
    }
  }
}

dir2.directive.ts

@Directive({
  selector: 'shopWindow'
})

export class ShopWindowDirective implements OnInit {
  @Input('script') param: any
  script: any

  constructor(private renderer:Renderer2) { }

  ngOnInit() {

    this.script = this.renderer.createElement('script')
    this.script.type = 'text/javascript'
    this.script.src = this.param
    this.script.async = true
    this.renderer.appendChild(document.head, this.script)

    document.write = function(input: string) {
      document.getElementById('shopwindow-container').innerHTML += input
    }
  }
}
angular
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5