ajax - Unexpected end of JSON input... SO Wants more info -


i'm confused... what's wrong this? couldn't post without changing title... don't know what's wrong

$(document).ready(function(){     $("#fmob").click(function(){         var mobname = $(this).attr("data-value");         console.log(mobname);         $.ajax({             type: "post",             url: "/system/mobproc.php",             data: {mobname: 1},             datatype: "json",             success: function(data){                 if(data.response === true){                     $("#fresponse").html(data.result);                   }else{                     $("#fresponse").html(data.result);                 }             },             error:function(jqxhr,textstatus,errorthrown ){               alert('exception:'+errorthrown );            }         });     }); }); 

i looked here unexpected end of json input ajax call

but somehow not expected... what's wrong? thanks.

try approach:

$(document).ready(function(){     $("#fmob").click(function(){         var mobname = $(this).attr("data-value");         console.log(mobname);         var data = {}; // setup data object         data[mobname] = 1; // add property key of value of "mobname" variable, data of 1 (per question)         $.ajax({             type: "post",             url: "/system/mobproc.php",             data: data, // pass data object post data instead of defining object inline             datatype: "json",             success: function(data){                 if(data.response === true){                     $("#fresponse").html(data.result);                   }else{                     $("#fresponse").html(data.result);                 }             },             error:function(jqxhr,textstatus,errorthrown ){               alert('exception:'+errorthrown );            }         });     }); }); 

note lines comments, above.

in approach, setup data object , specify property using value of "mobname" variable, instead of defining property inline. allows use dynamic value of variable key property.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -