ajax call in a post handler and ie trouble
I need to make a post after a succes of another post, but in internet explorer this not works. Suggest?
Seems that the $.ajax call in lwaAjax_getrsp works with all browsers but not with ie.
$('#LoginWithAjax_Register form').submit(function(event){
//Stop event, add loading pic...
event.preventDefault();
$('<div class="LoginWithAjax_Loading" id="LoginWithAjax_Loading"></div>').prependTo('#LoginWithAjax_Register');
//Sort out url
var url = $('#LoginWithAjax_Register form').attr('action');
//Get POST data
var postData = getPostData('#LoginWithAjax_Register form *[name]');
$.post(url, postData, function(data){
lwaAjax_getrsp(postData, data, 'LoginWithAjax_Register_Status', '#LoginWithAjax_Register' );
}, "json");
});
function lwaAjax_getrsp(posteddata, data, statusElement, prependTo ){
$('#LoginWithAjax_Loading').remove();
if( data.result === true || data.result === false ){
if(data.result === true){
//Login Successful
var dataString_getrsp = 'name='+ posteddata['user_login'] +
'&email=' + posteddata['user_email'] +
'&webform_id=' + 00001;
$.ajax({
type: 'POST',
url: "http://www.getresponse.com/add_contact_webform.html",
data: dataString_getrsp,
success: function(data){
$('#result2').html("<h2>"+data+"</h2>");
}
})
if( $('#'+statusElement).length > 0 ){
$('#'+statusElement).attr('class','confirm').html(data.message);
}else{
$('<span id="'+statusElement+'" class="confirm">'+data.message+'</span>').prependTo( prependTo );
}
}else{
//Login Failed
//If there already is an error element, replace text contents, otherwise create a new one and insert it
if( $('#'+statusElement).length > 0 ){
$('#'+statusElement).attr('class','invalid').html(data.error);
}else{
$('<span id="'+statusElement+'" class="invalid">'+data.error+'</span>').prependTo( prependTo );
}
var newrecoverylink = $('#custom_recovery_password').attr('href');
$('#LoginWithAjax_Status a').attr('href',newrecoverylink);
}
}else{
//If there already is an error element, replace text contents, otherwise create a new one and insert it
if( $('#'+statusElement).length > 0 ){
$('#'+statusElement).attr('class','invalid').html('An error has occured. Please try again.');
}else{
$('<span id="'+statusElement+'" class="invalid">An error has occured. Please try again.</span>').prependTo( prependTo );
}
}
}
The problem seems isn't on the ajax call in the handler but, after a new analysis on the external domain, it's possible that i.e block ajax call to external domains?
How to work around? Thanks all!
This not work and alert2 do not display.
$('#LoginWithAjax_Register form').submit(function(event){
//Stop event, add loading pic...
event.preventDefault();
$('<div class="LoginWithAjax_Loading" id="LoginWithAjax_Loading"></div>').prependTo('#Lo开发者_高级运维ginWithAjax_Register');
//Sort out url
var url = $(this).attr('action');
//Get POST data
var postData = getPostData('#LoginWithAjax_Register form *[name]');
$.post(url, postData, function(data){
lwaAjax_getrsp(postData, data, 'LoginWithAjax_Register_Status', '#LoginWithAjax_Register' );
}, "json");
window.alert("1");
$.post('http://www.getresponse.com/add_contact_webform.html', postData, function(data){
}, "jsonp");
window.alert("2");
});
This one works.
$('#LoginWithAjax_Register form').submit(function(event){
//Stop event, add loading pic...
event.preventDefault();
$('<div class="LoginWithAjax_Loading" id="LoginWithAjax_Loading"></div>').prependTo('#LoginWithAjax_Register');
//Sort out url
var url = $(this).attr('action');
//Get POST data
var postData = getPostData('#LoginWithAjax_Register form *[name]');
$.post(url, postData, function(data){
lwaAjax_getrsp(postData, data, 'LoginWithAjax_Register_Status', '#LoginWithAjax_Register' );
}, "json");
window.alert("1");
$.post('/', postData, function(data){
}, "jsonp");
window.alert("2");
});
精彩评论