我已经在这个问题上花费了 10 多个小时,基本上搜索了整个 Internet 以寻找解决方案。这是一个简单的 jQuery ajax POST 方法,我已经成功使用过几次。过去我也遇到过这个问题,但不知何故解决了。我传递的数据似乎没问题,在 chrome 的网络控制台中,它甚至显示了一个包含假定数据的成功帖子。但是,使用 .load 获取该数据始终返回 null。在下面的代码中,我使用了一个我阻止默认提交的表单来防止刷新。一个按钮触发 sellBook(),它会提示一个表单,之后提交会触发 post()。
JS
function sellBook(i) {
$('#results').html('');
title = books[i].title;
author = books[i].author;
ISBN = books[i].ISBN;
publisher = books[i].publisher;
image = books[i].image;
year = books[i].year;
$('#results').html('Listing for ' + books[i].title + ' by ' + books[i].author + '<br><br><form method="post" action="https://localhost/textbookexchange/db2.php" id="sellIt">Edition #: <input type="text" id="edition" name="edition"/><br><br>Price: $<input type="text" id="price" name="price"><br><br>Condition: <input type="text" id="condition" name="condition"><br><br><input type="submit" value="Submit"><br><br></form>');
getInfo();
$('#sellIt').submit(function () {
post();
return false;
});
}
function post() {
price = document.getElementsByName('price')[0].value;
edition = document.getElementsByName('edition')[0].value;
condition = document.getElementsByName('condition')[0].value;
var formData = {
A: title,
B: author,
C: ISBN,
D: publisher,
E: image,
F: year,
G: soldby,
H: fblink,
I: price,
J: edition,
K: condition
};
var url = 'db2.php/'
jQuery.ajax({
type: 'POST',
url: url,
data: formData,
success: function (data) {
alert(data);
$('#results').load("db2.php/");
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status + " " + thrownError);
},
});
}
我总是返回成功,从来没有返回错误,因为我收到有关数据的警报。
在我的 apache 错误日志中我得到了这个:
[2015 年 8 月 13 日星期四 11:24:15.666854] [:error] [pid 4255] [client 127.0.0.1:50476] PHP 注意:未定义索引:/var/www/html/textbookexchange/db2.php 中的 A在第 2 行,引用者:https://localhost/textbookexchange/
db2.php(the php file POSTED to)
<?php
echo $_POST['A'];
?>
我试过将其解析为 JSON、重置 contentType、设置 dataType、将 crossdomain 设置为 true、将 async 设置为 false、使用 jsonp、使用 $.post、使用更少的数据(只有一个变量)以及其他一些东西..
最佳答案
load() 创建一个单独的 get 请求,因此没有 POST 数据供 php 使用。您需要做的是使用从 post 请求返回的数据:
success: function(data) {
alert(data);
$('#results').html(data); //.load("db2.php/");
},
关于javascript - jQuery Ajax 方法成功,但没有收到数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31992880/
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
我想了解Ruby方法methods()是如何工作的。我尝试使用“ruby方法”在Google上搜索,但这不是我需要的。我也看过ruby-doc.org,但我没有找到这种方法。你能详细解释一下它是如何工作的或者给我一个链接吗?更新我用methods()方法做了实验,得到了这样的结果:'labrat'代码classFirstdeffirst_instance_mymethodenddefself.first_class_mymethodendendclassSecond使用类#returnsavailablemethodslistforclassandancestorsputsSeco
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案