我有一个包含JQuery UI Tabs小部件的网页.Tab小部件通过AJAX加载选项卡.在其中一个标签页(将其命名为DescriptionPage)中,我有一个将通过ajaxForm插件提交的表单.
<div id="tabs">
<ul>
<li>
<a href="DescriptionPage">Description Page</a>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的DescriptionPage的内容.
<form id="myForm">
<!-- Form elements goes here -->
</form>
<script>
$(function(){
$('#myForm').ajaxForm(function (response) {
$('#myForm').parent().empty().append(response);
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
提交表单后,将返回相同的DescriptionPage,包括表单和脚本.因此,表单内容将替换为服务器端的响应.响应还包含验证消息.
问题是,整个场景在Chrome和Firefox中运行良好.但在Internet Explorer 8中,会出现一个奇怪的问题.
首次加载选项卡时,javascript成功执行.当用户提交表单并且放置响应时,IE无法执行我的javascript,说"JQuery未定义".
为什么IE无法在通过ajax加载的内容中调用JQuery?有解决方法吗?
PS:我想从html中分离脚本,但它根本不是一个选项:(
P.S2:由于愚蠢的IE,我的javascript和CSS文件变得一团糟.
我一直在寻找解决方案,但我找不到答案.
我创建了一个图片上传表单.它使用ajaxform插件运行.但它仍然没有上传到目录.error_log说
move_uploaded_file()无法将文件从[tmp]移动到[dir].
然后在前端显示上传完成.但是当调用文件时,它不存在.
HTML代码:
<div class="imgupload hidden">
<form id="profpicform" action="" method="post" enctype="multipart/form-data">
<input type="file" size="60" name="profpic">
<input type="submit" value="Submit File">
</form>
<div class="imguploadStatus">
<div class="imguploadProgress">
<div class="imguploadProgressBar"></div>
<div class="imguploadProgressPercent">0%</div>
</div>
<div class="imguploadMsg"></div>
</div>
<div class="imgpreview"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
JS:
var options = {
beforeSend: function()
{
$(".imguploadProgress").show();
$(".imguploadProgressBar").width('0%');
$(".imguploadMsg").html("");
$(".imguploadProgressPercent").html("0%");
},
uploadProgress: function(event, position, total, percentComplete)
{
$(".imguploadProgressBar").width(percentComplete+'%');
$(".imguploadProgressPercent").html(percentComplete+'%');
},
success: function()
{
$(".imguploadProgressBar").width('100%');
$(".imguploadProgressPercent").html('100%');
},
complete: function(response)
{
alert('Complecion');
},
error: function()
{
$(".imguploadMsg").html("<font color='red'> ERROR: unable to upload files</font>"); …Run Code Online (Sandbox Code Playgroud) 我试图在jQuery Mobile网站上通过ajax提交一个简单的登录表单,但我遇到了麻烦.
看来,当我提交表单(通过POST)时,表单参数会被添加到url中.不仅如此,他们还删除了表单提交前我所处的锚定页面.
例如,我在页面上 localhost:8080/myapp/#sign_up
然后我提交表单,导致网址成为: localhost:8080/myapp/?email=a@a.com&pass=pass
因此,如果我点击验证错误并单击"后退"按钮,我就不会返回到#sign_up页面.
有任何想法吗?
我目前正在使用ASP.NET Web API将ASP.NET MVC网站的某些部分升级为更加RESTful.我们正在转向更RESTful设计的功能之一是文件上传.对于客户端,我们使用jquery插件ajaxForm来包装iframe的创建,iframe将提交包含文件输入元素的表单.这对ASP.NET MVC很有用.
当更改它以使用我们的Web API端点(它返回Content-Type为"application/json"的响应)时,我们注意到Internet Explorer 9的问题.似乎从未调用过ajaxForm成功函数.据我所知,似乎IE中的iframe将Content-Type为"application/json"的响应正文解释为要下载的文件附件.这意味着它永远不会触发iframe的"已加载"事件,这意味着永远不会触发ajaxForm onload事件处理程序,并且永远不会调用我们的ajaxForm成功函数.
我们也注意到了IE 7中的问题,但是我们无法在最新版本的Firefox或Chrome中重新创建该问题,即使强迫他们使用iframe而不是使用FormData的File API.
为了解决此问题,我现在强制将响应Content-Type返回到"text/plain",这是我们之前从处理文件上载的ASP.NET MVC控制器操作返回的内容.这使一切都恢复了.
我的问题:
附加限制:我不能在本网站上使用ActiveX或Flash.我可以使用不同的插件,但前提是它具有一般的跨浏览器支持.(IE,Chrome,Firefox,Safari等)
我的HTML:
<form id="uploadFormId" action="" method="post" enctype="multipart/form-data" encoding="multipart/form-data">
<input type="file" name="files[]"/>
</form>
Run Code Online (Sandbox Code Playgroud)
我的javascript:
function onFileChange( e ) {
if ( e.type === e.originalEvent.type ) {
var filePath = $( e.currentTarget ).val();
if ( filePath !== '' ) {
$( this ).closest( 'form' ).submit();
}
}
};
$( function() {
$( '#uploadFormId' ).ajaxForm( {
url: "api/Files/1234",
dataType: 'json',
success: …Run Code Online (Sandbox Code Playgroud) 我在智能模板中有一个过滤器表单,如下所示:
<form id="view-questions-form" name="user_transactions" action="{$control_url}modules/transactions/view_transactions.php" method="post">
<div class="w50">
<ul>
<li>
<label>From Date</label>
<div class="form-element">
<input type="text" class="cal fl-left" id="frmDate" name="from_date" value="{if $from_date}{$from_date}{else}{$today_date}{/if}" maxlength="10">
</div>
</li>
<li>
<label>Transaction No.</label>
<div class="form-element">
<input type="text" name="transaction_no" id="transaction_no" class="" value="{if $transaction_no}{$transaction_no}{/if}" maxlength="50">
</div>
</li>
</ul>
</div>
<div class="w50">
<ul>
<li>
<label>To Date</label>
<div class="form-element">
<input type="text" name="to_date" id="toDate" class="cal" value="{if $to_date}{$to_date}{else}{$today_date}{/if}" maxlength="10">
</div>
</li>
<li>
<label>Discount Code</label>
<div class="form-element">
<input type="text" name="userName" id="userName" class="">
</div>
</li>
</ul>
</div>
<div class="w50">
<ul>
<li>
<label>Status</label>
<div …Run Code Online (Sandbox Code Playgroud) 我想通过 jQuery 请求发送文件post。我的 node.js 将读取该文件并插入data到 Mongodb 中。
这是我的 node.js 函数:
upload: function(req, res){
var FileName;
req.file('myFile').upload(function(err,files){
var i = 1;
if(err) return res.serverError(err);
FileName = files[0].filename; ......
Run Code Online (Sandbox Code Playgroud)
post如果直接从html以下位置发送请求,上述函数可以正常工作:
<form method="post" action="/indi id="indiform" enctype="multipart/form-data">
<input type="file" name="myFile" id="myIndifile"/>
<input type="submit" id="indisubmitbutton" value="Submit" name="upload" class="btn btn-primary" id = "uploadFile"/>
</form>
Run Code Online (Sandbox Code Playgroud)
现在我想提交post来自 jQuery 的请求并将响应处理data为:
var file = $("#myIndifile")[0].files[0];
$.ajax({
type: 'post',
url: '/indi',
async: false,
data: JSON.stringify({ myFile:file }),
contentType: "application/json",
success: …Run Code Online (Sandbox Code Playgroud) 我正在尝试更新数据库中的记录而不刷新表单.我有grid.php页面与表单来显示和更新记录.然后,我有一个文件update.php与UPDATE查询.第三个文件是js1.jsAJAX代码.如果我映射grid.php到update.php通过action=update.php,更新询问的伟大工程.但是一旦我尝试包含js1.js文件以防止表单刷新,它就会停止工作.
代码如下:
grid.php
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="j1.js"></script>
<?php //query.php
require_once 'header.php';
if (!$loggedin) die();
$query = "SELECT SpringMgmt.SpringMgmtID,
SpringMgmt.SpringMgmtActiveYear,
SpringMgmt.PoolID,
SpringMgmt.Notes,
SpringMgmt.SOIEstSubmitted,
SpringMgmt.EstAdditional,
SpringMgmt.SOIMeetingScheduled,
Pool.Pool,
Pool.AreaManager,
Employees.EmployeeID,
Employees.FirstName
FROM SpringMgmt
INNER JOIN Pool ON SpringMgmt.PoolID = Pool.PoolID
INNER JOIN Employees ON Employees.EmployeeID = Pool.AreaManager ";
$result = mysql_query($query);
echo "OK</div>";
if (!$result) die ("Database access failed0: " . mysql_error());
//TABLE AND ITS HEADING
echo …Run Code Online (Sandbox Code Playgroud) 在 React.js 中创建我的第一个应用程序,并希望使用 Ajax 将联系表单提交到电子邮件。我已经使用这个解决方案作为指导:https : //liusashmily.wordpress.com/author/liusashmily/但完整的组件文件不可用,只有部分,我无法联系到作者。
// Create Component
class Contact extends React.Component {
constructor(props){
super(props);
this.state = {
contactEmail: '',
contactMessage: ''
};
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
this.handleChangeMsg = this.handleChangeMsg.bind(this);
}
handleChange(event) {
this.setState({
contactEmail: event.target.value,
});
}
handleChangeMsg(event) {
this.setState({
contactMessage: event.target.value
});
}
handleSubmit(event) {
event.preventDefault();
this.setState({
type: 'info',
message: 'Sending…'
});
$.ajax({
url: 'php/mailer.php',
type: 'POST',
data: {
'form_email': this.state.contactEmail,
'form_msg': this.state.contactMessage
},
cache: false,
success: function(data) {
// Success.. …Run Code Online (Sandbox Code Playgroud)在我的 WordPress 网站上,我有一个使用 AJAX 和 PHP 将文本转换为音频的表单。更新转换后的文本时,文件名保持不变,只是重新创建文件。
一切似乎都工作正常,除了当我更新文本时要播放的音频源没有重新加载/刷新。
默认下载按钮为我提供更新的文件,如果我刷新整个页面,我只能听到更新的文件播放。
我的代码(为了相关性而简化)--
jQuery(document).on('click', '#savetext', function(e) {
e.preventDefault();
var myVideo = $('#player');
var path = $("#path").val();
myVideo.src = path;
$.ajax({
data: {
action: 'polly_pros',
pollytext: txt,
rate: rate,
voice: voice
},
type: 'post',
url: polpro.ajax_url,
cache: false,
success: function(data) {
console.log(data);
myVideo.load();
myVideo.get(0).play();
},
error: function() {
console.log("Error");
}
});
});
Run Code Online (Sandbox Code Playgroud)
<audio id="player" controls>
<source id="audiosource" src="<?php echo $thepath; ?>" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<textarea name="pollytext" id="pollytext"></textarea> …Run Code Online (Sandbox Code Playgroud) 我想在ASP.net MVC 2.0应用程序中这样做.我有一个包含两个字段number1和number2的表单.
我想使用ajax请求添加这两个数字.在控制器中,我收到两个数字,添加它们并将结果存储在另一个字符串中.那么,我这样做:
[HttpPost]
public string TestAjax(FormCollection form)
{
int strnum1 = Convert.ToInt32(form["txtbox1"].ToString());
int strnum2 = Convert.ToInt32(form["txtbox2"].ToString());
string strnum3 = Convert.ToString(strnum1 + strnum2);
if (strnum3 != null)
{
return "<script>alert("some message")</script>";
}
return string.Empty;
}
Run Code Online (Sandbox Code Playgroud)
是否可以从控制器操作以字符串的形式返回java脚本