Strange behavior using $ ('. Ajax_form'). ajaxForm ();

I first applied jquery ajaxForm to a class like the following

<form class="ajax_form"...><input type="text" name="q" /><input type="submit" /></form>
<form class="ajax_form"...><input type="text" name="q" /><input type="submit" /></form>

<script>
$('.ajax_form').ajaxForm({
  dataType: 'json',
  error: ajaxErrorHandler,
  success: function(response) { // do some ui update .. }
});
</script>

Now, after the Ajax call ends, I always fall into the error area , although firebug did not report any errors, I'm not sure what I did wrong.

+3
source share
6 answers

, , , . "multipart/form-data" Firefox, jquery.form iframe . Content-Type /, iframe <pre> , jquery json parser , Firebug json .

, ( : http://www.extjs.com/forum/archive/index.php/t-17248.html).

, , Content-Type "text/html" ( , ).

+11

@c.sokun: , . ( ... ?)

FireBug ? !

+1

json. , . .

, . :

url = url + "?" + $(".ajaxForm").serialize();
$(".ajaxForm").ajax({url: url, dataType: "json", type : "post",
                    success: function(response) {},
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log(textStatus);
                        console.log(errorThrown);
                    }});

- " ".

+1

, URL- -?

jquery.com:

$("#myform").ajaxForm({
   url: "mypage.php",
   type: "POST"
 });
0

ajaxErrorHandler ? , . jQuery jQuery ?

, . "test.json", "{test:" hello world "}" , :

<script type="text/javascript" src="http://malsup.com/jquery/jquery-1.2.6.js"></script>
<script type="text/javascript" src="http://malsup.com/jquery/form/jquery.form.js?2.28"></script>

<form class="ajax_form" action="test.json" method="post"><input type="text" name="q" /><input type="submit" /></form>
<br/>
<form class="ajax_form" action="test.json" method="post"><input type="text" name="q" /><input type="submit" /></form>

<script>
$('.ajax_form').ajaxForm({
  dataType: 'json',
  error: function() {alert("error");},
  success: function(response) {alert(response.test);}
});
</script>
0

, API , "", , , . .

0

Source: https://habr.com/ru/post/1709056/


All Articles