Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Catch and format to json with Jquery

Posted on 2015-01-08
2
Medium Priority
?
45 Views
Last Modified: 2016-05-12
Good day people, i'm having some problems with collecting the data i am passing via jquery's ajax post method.
So far i achieve to connect to the backend servlet with no parameters. No i must pass the data collected in a json (or any avaible) format.

the tags in html are the following

<ul class="user-tags"> 
<li value="124506">
<span class="acc">100</span>
<span class="skill">java</span>
<div >
	<input class="btn" type="button" value="+" />
</div>
<span>
	<strong>
		other stuff
	</strong>
</span>
</li>
<li value="24869701">
	<span class="acc">105</span>
	<span class="skill">sql</span>
	<div>
		<input class="btn" type="button" value="+" />
	</div>
	<span>
	<strong>
		other stuff
	</strong>
	</span>
</li>
</ul>

Open in new window


I would like to send those <span> when the proper button is clicked, if possible on json or any other viable format.
each <li> element has a value, and a <span> with the values i want to send....

how do i collect the clicked row values with jquery???
i am not a ninja on front-end things.. yet!
0
Comment
Question by:JavierVera
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
Rob earned 2000 total points
ID: 40539280
This should get you started: http://jsbin.com/zewige/1/edit?html,js,output

I've also changed the 'value' attribute of the <li> tags to a data attribte as you can't have 'value' as an attribute

var items = [];

$(function() {
  $('.btn').on('click', function(e) {
    var me = $(e.target);
    // disabled the button to allow only once
    me.prop('disabled', 'disabled');
    
    var parent = me.parents('li');
    
    items.push({
      acc: parent.find('.acc').text(),
      skill: parent.find('.skill').text(),
      val: parent.data('value')
    });
    
    console.dir(items);
    
  });

  $('#submit').on('click', function() {
    $.ajax({
      url: '/your/url',
      data: {
        values: JSON.stringify(items)
      }
    });
  });
});

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question