When I ajaxSubmit a form, the service returns a number. For some reason, ajaxSubmit seems to add a bunch of tags to it.
form.ajaxSubmit(function(data){
alert(data);
});
});
Here, the alert prints out: "<head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">130</pre></body>"
Whereas if I check in my 开发者_如何学Cdebugger, the value is simply 130.
I have made the assumption that since the service seems to return a correct value, this issue is caused only on the clientside. Please correct me if I'm wrong.
Why is the value different in the javascript from that in the response?
The problem was that jquery.form doesn't expect to receive plaintext, it expects either JSON, XML, HTML or Script.
So I solved this by sending JSON-data from the serverside, and specifying that JSON was the expected format at the clientside.
form.ajaxSubmit(
{dataType: 'json',
success: function(data) {
alert(data) });
I'm guessing you're using this jQuery Form Plugin. Its API states:
Note: You can pass any of the standard $.ajax options to ajaxForm
Have you tried passing it the dataType
option? Like this:
form.ajaxSubmit({
dataType: 'text',
success: function(data){ alert(data); }
});
精彩评论