javascript - jQuery object in JSON value -


Here's my first question!

I'm calling through AJAX through AJAX in the client side The verification library library tells me to specify that, for the current rule, I want to insert the error message. For my valid verification rules, I can write an object:

  {'errorlocation': jQuery ('[name = "foo"]'). The nearest ('. Bar')}   

My accreditation library allows me to inject after the first init and the rules, so when I submit my model by REST, then I I can get server response with errors I am currently developing that server response I would like that the error response will be an array of validation rules so that I can later inject those rules into the same verification object which has already been created on my page. Therefore, in response to Jason's, I would need a definition like that in the code snippet above.

It seems that backbone and jargon pars can not evaluate Jason algorithms jQuery () , although the value of the object is definitely available in the global namespace. So it does not work:

  jQuery.parseJSON ("{'errorlocation': jQuery ('[name = \" foo \ "]'). Nearest ('. Bar')} ");   

I've thought about accumulating "[name = 'foo']" and jacking after parse, but it does not work for the case where I want to chain Do I know about the JSON parser, which will parse / allow the variable located in the global namespace, such as .closest ('. Bar') above

?

JSON is a data format, not code format. Normally you want to put your system in such a way that you are sending the data to the server to the server, and then your customer uses the data to determine an action. Then you might have to pass foo and .bar back into the data form, and to determine how to run the function.

If you really are designing it this way, and I recommend against it, you can use eval to evaluate an arbitrary string as javascript:

  var errorInfo = jQuery.parseJSON ("{'errorlocation': \" JQuery ('[name = \ "foo \"]'). Nearest ('bar') \ "}"); Eval (errorInfo.errorocation);    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -