4. Poll results through JS-callback

This functional is not available for Internet Explorer of under 8 version and some mobile browsers

Several conditions are required for getting of poll results form Simpoll API by your JavaScript function:

  1. Enabled option «Enable sending of results» in poll settings;
  2. JS selected in «Transfer method» field;
  3. The poll should be inserted on your site page (code for insertion can be obtained at «Sharing» section on «Insert on site» tab);
  4. simpollCallback() function should be defined with one input parameter on the same page.

Argument of functionsimpollCallback() will be the object features of which contain information on poll results.

Example of function simpollCallback():


					function simpollCallback(result){

						alert('Poll ID: ' + result.sp_survey_id);
						alert('Respondent name: ' + result.sp_resp.name);

						if (result.sp_resp.quiz_passed == 1){
							alert('Respondent has passed the test');
						} else {
							alert('Respondent has failed the test');
						}

					}

				

Example of argument of function simpollCallback():


					{
						"sp_survey_id": "551",
						"sp_survey_key": "aa7ca07e",
						"sp_resp": {
							"id": "172712",
							"ip_addr": "127.0.0.1",
							"name": "Respondent #172712",
							"time_start": "2011-12-13 16:17:00",
							"time_end": "2011-12-13 16:17:13",
							"time_delta": "00:00:13",
							"quiz_passed": "0",
							"quiz_percent": "0",
							"quiz_correct": "1",
							"quiz_wrong": "3"
						},
						"sp_result": "1",
						"sp_answers": {
							"1": ["Spain"],
							"2": ["Pyramids", "Kremlin", "Colosseum"]
						}
					}

				

Names, structure and values of transferred object features are absolutely identical to those described in 3.2.

If there are several Simpoll polls inserted on the page, then simpollCallback() function will still exist in single copy. The poll that has sent the results can be checked inside the function, on the basis of sp_survey_id field in received object.