jQuery and Form
inside posting page
function postToError(CBaseError)
{
var e =encodeURI(JSON.stringify(CBaseError.errors).replace(/"/g,'"'));
//way 1
$('<form action="./ErrorP" method="post"><input name="error"
type="hidden" value="'+e+'"></form>').appendTo('body').submit();
//way 2
var newForm = $('<form>', {
'action': './ErrorP',
'method': 'post'
}).append($('<input>', {
'name': 'error',
'value': e,
'type': 'hidden'
}));
newForm.appendTo('body');
newForm.submit();
}
inside page posted to
<script>
var Error={"errors":[]};
var e = '@ViewData["Error"]';
e = e.replace(/"/g,'"');
var a = decodeURI(e);
Error.errors=JSON.parse(a);
$.each(Error.errors, function (i, item) {
$.each( item, function( key, value ) {
$("#headerErr ul").append('<li><span class="tab">'+key+' :'+value+'</span></li>');
});
});
$("#responseAlert").text(a);
</script>
http://jsfiddle.net/YqGLH/626/
http://jsfiddle.net/purmou/A9qXe/
https://stackoverflow.com/questions/8003089/dynamically-create-and-submit-form
评论
发表评论