使用PHP脚本发布ajax请求

问题描述 投票:0回答:2

我正在尝试测试一个ajax post请求,它接受我的formData对象并通过PHP脚本运行它(我不知道任何PHP,但是在问题中提供了脚本)。

所以我在我的本地驱动器上有一个名为index.php的PHP文件(我使用的是Ubuntu),应该发生的是我发布了formData对象并创建了一个report.txt文件,可以通过访问http://copypaste.test来访问。我坚持如何在我的电脑上本地创建域名。

Selenium.prototype.doSaveCopyPaste = function(locator) {
 var text = jQuery(locator).text();

 var formData = new FormData();
 formData.append('report', text);

 var ajax = jQuery.ajax({
  type: "POST",
  url: 'http://copypaste.test',
  data: formData,
  dataType: 'text',
  processData: false, 
  contentType: false,
    success: function(){ 
      console.log('success'); 
    },
    error: function() {
     console.log('error'); 
    } 
  });
  console.log(ajax) 
 }
php jquery ajax ubuntu selenium
2个回答
1
投票

您需要在本地计算机上运行的Web服务器接受传入的HTTP请求,并执行使用客户端/浏览器/ JavaScript中的输入数据的PHP脚本并发回响应。

正如#Esil Stavenga所写,使用XAMPP是一种选择。

它包括一个Web服务器(Apache)和一个PHP解释器。

您可能需要在浏览器/客户端输入其IP地址,而不是通过域名(如http://copypaste.test)访问本地PC。


2
投票

您可以使用任何Web服务器来设置本地服务器。一些常见的是xampp,wampServer等this tutorial很好地解释了如何设置xampp

© www.soinside.com 2019 - 2024. All rights reserved.