I’m a newlye developer rails application and Coffescript
I have this CoffeScript code to get some data using ajax with the get method and json:
jQuery ->
$("#detalleliquidacion_nit").change ->
campo1 = document.getElementById("detalleliquidacion_nit")
document.getElementById("detalleliquidacion_proveedor_id").value = ""
document.getElementById("detalleliquidacion_nombreproveedor").value = ""
jQuery.getJSON "/proveedores/obtenerdatos/" + campo1.value, (data) ->
$("#detalleliquidacion_nombreproveedor").val data[0].nombreproveedor
$("#detalleliquidacion_proveedor_id").val data[0].id
false
I want to know if the ajax is empty.
I tried adding this code after the “false” sentence:
campo2 = document.getElementById("detalleliquidacion_proveedor_id").value
alert campo2 if campo2 is ""
But allways return true, because the input field in the form, and this point, still empty.
My enviroment is: rails 3.2.6; ruby 1.9.3p194
How I can know if the ajax return is empty?
Some suggestions will be appreciate.
Regards.
I’m not sure I’ve correctly understood your question, but it looks like you want to know if the JSON value returned is false or would like to see what is inside of it.
Try something like this
using
jQuery.ajaxallows you more granular control over your returned data than the convenience methodjQuery.getJSONconsole.logwill output to the Development Console and can help you debug. You can also use the more advanced javascript debugging features in Chrome and Safari to set breakpoints and see values of variables at runtime