My ajax response returns an empty response (ie with multiple lines of blank spaces) and i want to check that in my success function. How to check for empty json response with regex in javascript?
> /^\s*$/.test("foo")
false
> /^\s*$/.test("")
true
> /^\s*$/.test(" ")
true
> /^\s*$/.test("\n\n")
true
jQuery.ajax
datatype to text
Create the following success
callback
$.ajax({ // other options.. dataType: 'text', success(planinTextData) { if (planinTextData !== '') { var data = JSON.parse(planinTextData); } } });
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.