jQuery $ .post()+ IE8 [英] jQuery $.post() + IE8
问题描述
<script type="text/javascript" src="/scripts/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.form.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#SendReply").click(function(){
$(".error").hide();
var hasError = false;
var pathname = window.location.pathname;
var random = Math.random();
var messageVal = $("#InquiryResponse").val();
if(messageVal == 'Type your response in this space ...') {
$("#InquiryResponse").after('<span class="error"><br><br><font color="red">You forgot to type your response to the inquiry. Please type it in the above space and submit again.</font><br></span>');
hasError = true;
}
if(hasError == false) {
$(this).hide();
if (jQuery.browser.msie != true) {
$.post( "",
{ Detail: messageVal},
function(data) {
//alert("For non IE");
$("#InqRespForm").slideUp("slow", function() {
$("#InqRespForm").before('<h1>Success</h1><p><font color="green">Your message has been sent.</font></p>');
});
});
}
if (jQuery.browser.msie == true) {
jQuery.ajaxSetup({async:false});
$.post( pathname , { Detail: messageVal},function(data)
{
$("#InqRespForm").width($("#InqRespForm").parent().width()).slideUp("slow");
$("#InqRespForm").before('<h1>Success</h1><p><font color="green">Your message has been sent.</font></p>');
});
jQuery.ajaxSetup({async:true});
}
}
return false;
});
});
</script>
<form action="" method="post" id="InqRespForm" name=InqRespForm>
Reply to the above Inquiry : <br/>
<textarea rows="7" name="Detail" id="InquiryResponse" cols="60" colspan=2>Type your response in this space ...</textarea>
<br/>
<input id="SendReply" name="Send" type="submit" value="Send Response" alt="Reply to Inquiry" />
</form>
在表单提交时,我发送一封电子邮件。这适用于FF,Chrome等。但我已经秃头试图在IE8中完成这项工作。如果你能给我一个解决方案,我会给你买啤酒。
On form submit, I send an email out. Which works on FF, Chrome etc. But I've gone bald trying to make this work in IE8. I will buy you beer if you can point me to a solution.
推荐答案
我想通了。我将在这里发布解决方案,以防将来帮助某人。问题在于我发布的网址。我的网址是一个参数化网址,我一直使用错误的语法/格式。实际上并不需要IE和非IE分离。答案在于提取当前url的各种组件,并通过data数组将其传递给$ .post。感谢您的投入。下面的工作代码:
I figured it out. Im going to post the solution here in case it helps someone in future. The problem was with the url i was posting to. My url was a parameterised url and I was using a wrong syntax/format all along. The IE and non IE separation is not really needed. The answer lies in extracting the various components of the current url and pass it in $.post via the "data" array. Thanks for your inputs. Working code below:
<script type="text/javascript" src="/scripts/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.form.js"></script>
<script type="text/javascript" src="/scripts/jquery.url.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#SendReply").click(function(){
$(".error").hide();
var hasError = false;
var pathname = window.location.pathname;
var random = Math.random();
var kar_ = $.url.param("kar");
var obj_ = $.url.param("obj");
var me_ = $.url.param("me");
var messageVal = $("#InquiryResponse").val();
if(messageVal == 'Type your response in this space ...') {
$("#InquiryResponse").after('<span class="error"><br><br><font color="red">You forgot to type your response to the inquiry. Please type it in the above space and submit again.</font><br></span>');
hasError = true;
}
if(hasError == false) {
$(this).hide();
$.post( "inqdetails.asp",
{ Detail: messageVal, kar: kar_, obj: obj_, me: me_},
function(data) {
$("#InqRespForm").slideUp("slow", function() {
$("#InqRespForm").before('<h1>Success</h1><p><font color="green">Your message has been sent.</font></p>');
});
});
}
return false;
});
});
</script>
这篇关于jQuery $ .post()+ IE8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!