javascript - Ajax function doesn't execute when any of the input fields are not supplied in django -
i have below ajax function, working fine when input values fields, doesn't work when not supply value of 3 fields (pname,psection, , rinput-json)
<script type="text/javascript"> function saveprof() { $('.spinner').show(); $.ajax({ type: "post", url: "saveprof", enctype: 'multipart/form-data', async: true, data: { 'pname_aj': $('#pname').val(), 'psection_aj': $('#psection').val(), 'rinput_aj' : json.stringify(fun()), 'csrfmiddlewaretoken': $("input[name=csrfmiddlewaretoken]").val() }, success: function (data, textstatus, jqxhr) { $('#message').html(data); window.location.href = 'myprofile'; window.location('myprofile'); $('.spinner').fadeout(); } }); } </script>
how can make work if values of fields not supplied ?
for information, call made django view save fields in database.
it sounds values optional?
if so, perhaps can check see if values exist, , if not, submit empty string:
data: { 'pname_aj': ( $('#pname').val() || ""), 'psection_aj': ( $('#psection').val() || ""), 'rinput_aj' : (json.stringify(fun()) || ""), 'csrfmiddlewaretoken':$("input[name=csrfmiddlewaretoken]").val() },
so if user has entered values in sections (and fun()
returns can stringified, variables submitted. otherwise, empty string gets submitted.
Comments
Post a Comment