javascript - Ajax calls, sending images and other data -
i wondering there length limit it? im sending images , data server, returns cannot "find" required data. can , cant find it. , getting frustrating because cant find problem. im sending images dataurl. server gets nothing. there empty formdata checking inspection tool data writen correctly.
any other things check?
posting code:
var id = this.id.substr(11); if (!user) { if (document.getelementbyid('username').value.length < 1) { listing.alert('{{trans('adsadd.entername')}}', true); $('#username').parent().addclass('has-error'); $('#username').addclass('has-error'); return; } if (document.getelementbyid('userphone').value < 1) { listing.alert('{{trans('adsadd.enterphone')}}', true); $('#userphone').parent().addclass('has-error'); $('#userphone').addclass('has-error'); return; } if (document.getelementbyid('usercity').value < 1) { listing.alert('{{trans('adsadd.entercity')}}', true); $('#usercity').parent().addclass('has-error'); $('#usercity').addclass('has-error'); return; } if (document.getelementbyid('useremail').value < 1) { listing.alert('{{trans('adsadd.enteremail')}}', true); $('#useremail').parent().addclass('has-error'); $('#useremail').addclass('has-error'); return; } } if (document.getelementbyid('price-' + id).value.length < 1) { listing.alert('{{trans('adsadd.enterprice')}}', true); $('#price-' + id).parent().addclass('has-error'); $('#price-' + id).addclass('has-error'); return; } if (document.getelementbyid('description-' + id).value.length < 1) { listing.alert('{{trans('adsadd.enterdescription')}}', true); $('#description-' + id).parent().addclass('has-error'); $('#description-' + id).addclass('has-error'); return; } var formdata = new formdata(); var images = []; $('#img-div-' + id).find('.img-outer-div').each(function (index, imgelement) { var img = $(imgelement).find('.item-image'); images.push(img.attr('src')); }); formdata.append('images', json.stringify(images)); formdata.append('category', document.getelementbyid('category-' + id).options[document.getelementbyid('category-' + id).selectedindex].text); formdata.append('price', document.getelementbyid('price-' + id).value); formdata.append('description', document.getelementbyid('description-' + id).value); formdata.append('time', document.getelementbyid('time-' + id).selectedindex); formdata.append('type', (document.getelementbyid('type-' + id) != null) ? document.getelementbyid('type-' + id).selectedindex : 0); formdata.append('lang', '{{app::getlocale()}}'); if (!user) { formdata.append('username', document.getelementbyid('username').value); formdata.append('userphone', document.getelementbyid('userphone').value); formdata.append('usercity', document.getelementbyid('usercity').value); formdata.append('useremail', document.getelementbyid('useremail').value); } formdata.append('id', id); $(this).attr('disabled', 'true'); var req = new xmlhttprequest(); req.open('post', '/items/add'); req.send(formdata); req.addeventlistener('load', function () { var obj = $.parsejson(req.response); if (obj['message'] != null) { if (obj['message']['email']) { listing.alert(obj['message']['email'], false); } else if (obj['message']['phone']) { listing.alert(obj['message']['phone'], false); } else if (obj['message']) { listing.alert(obj['message'], false); } } var id = obj['id']; var item = $('#item-' + id); if (obj['success']) { item.empty(); item.append('<div class="alert alert-box" id="alert">{{trans('adsadd.done')}}</div>'); item.fadeout(4000); if (!user) { window.location.replace("{{url::route('home-index')}}"); } } else { item.find('button').prop('disabled', null); item.find('button').innerhtml = '{{trans('adsadd.send')}}'; } }); this.innerhtml = '{{trans('adsadd.sending')}}';
and php code:
$message = null; // message user $locale = input::get('lang'); // item $data = array( 'category' => input::get('category'), 'price' => input::get('price'), 'description' => input::get('description'), 'images' => json_decode(input::get('images')), 'time' => input::get('time'), 'type' => (input::get('type') == null) ? 0 : input::get('type'), ); $validator = validator::make($data, array( 'description' => 'required', 'price' => 'required', 'category' => 'required', 'images' => 'required|max:10', 'time' => 'required', 'type' => 'required', )); if($validator->fails()) { return response::json(['success' => false, 'message' => $validator->errors()->first()]); }
it gets part validator fails. if dosnt fail, , data actualy sent server saves , good.
if helps can give link webpage can checked out.
edit------------- seems pictures cannot sent. individualy , others. , pictures can sent individualy not other. , pictures can sent individualy , other pictures can sent. really weird.
so true answer @barmar said. looked @ size of files i'm sending , seemed alright, didn't think didn't send images files data-url. , means file size didn't matter. , had increase actual post size.
Comments
Post a Comment