Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8043673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:58:50+00:00 2026-06-05T04:58:50+00:00

Please help. I implemented a function on jQuery, which sends data (JSON object), but

  • 0

Please help. I implemented a function on jQuery, which sends data (JSON object), but I can not get a correct answer because of a problem with the encoding. >>>>>>>>>The site is encoded: AJAX file: UTF-8

JS:

function loadvariant (hash)
{
var id_quest = $("#sel_quest").val();
var nocache = Math.random();
// Отправляем ajax запроc
  $.ajax({
    type: "POST",
    url: "/wp-content/plugins/votefe/php/ajax/loadvote.php",
    data: {hash:hash,id_quest:id_quest,nocache:nocache},
    dataType: "json"
  }).done(function(msg) {
    if (msg['return']==1) {
        $('#tab_svariant .ovar').remove();
        for (var i=0;i<msg['variant'].length;i++) {
            var html = "<tr class='ovar'><td>"+msg['variant'][i]['id']+"</td>
<td>"+msg['variant'][i]['param']+"</td><td>"+msg['variant'][i]['style']+"</td><td>
<input type=\"checkbox\" name=\"id_variant_"+msg['variant'][i]['id']+"\">
</td></tr>";
            $('#tab_svariant').append(html);
        }       
  return true;
 } else {
  alert(msg['return']+ " - Внутрення ошибка сайта. Попробуйте перезагрузить страницу, или
 обратитесь к разработчикам");
  return false;
    }
  });  
}

PHP:

session_start();  
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: application/json; charset=utf-8');
include_once("../voteconf.php");
$results = array();
$results['return'] = 0;
//$results['variant'] = array();

$dbname = "two"; # Имя базы данных
$username = "fedor"; # Имя пользователя в БД
$host = "127.0.0.1"; # Хост MySQL сервера
$passw = "353488"; # Пароль к БД

$link = mysql_connect($host, $username, $passw);
if (!$link) $results['return'] = 2;
$db_selected = mysql_select_db($dbname, $link);
if (!$db_selected) $results['return'] = 3;

# Возвращаемые значения / ошибки
# 0 - Скрипт не отработал
# 1 - return ok (все хорошо)
# 2 - не соединился с базой
# 3 - не смог выбрвть базу.
# 4 - не верный хеш
# 5 - Не удалось получить ID вопроса.
# 6 - Ошибка запроса выборки

$hash = md5(VOTESECR);
if ($hash!=$_POST['hash']) $results['return'] = "4787 > ".$hash." > ".$_POST['hash'];

if (!isset($_POST['id_quest']) || $_POST['id_quest'] =='')  $rezults['return'] = 5;

$id_quest = mysql_real_escape_string(htmlspecialchars($_POST['id_quest']));
if ($results['return'] == 0){
 $sql = "SELECT v.id as id, v.param as param, s.name as style FROM wp_s_variant v LEFT JOIN 
 wp_s_style s ON v.id_style=s.id WHERE v.id_quest= '".$id_quest."'";
 $res_variant = mysql_query($sql);
 if (!$res_variant) $results['return'] = 6;
 else {     
while ($rv = mysql_fetch_assoc($res_variant)) {
    $results['variant'][] = $rv;
}
$results['return'] = 1;     
 }
}

$json=json_encode($results);
echo $json;

html

<table id="tab_svariant">
  <tr>
    <th width="30px">ID</th>
    <th width="300px">Вариант ответа</th>
    <th width="400px">Стиль</th>
    <th width="60px">Выбрать</th>       
 </tr>
</table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:58:51+00:00Added an answer on June 5, 2026 at 4:58 am

    Try enter the “contentType” in options of jQuery.ajax:

    $.ajax({
      type: "POST",
      url: "/php/ajax/loadvote.php",
      data: {id_vote:id_vote,nocache:nocache},
      dataType: "json",
      contentType: "utf-8"
    }).done(function(msg) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page in which i can successfully use the jquery focus function
I don't know how can i validate the recaptcha thing via jQuery. Please help.
Please help me: create clickable regions in the canvas below that I can assign
Please help. I've got an error while deserializing the data from the server, The
Can you any please help me on this. I have a master table [item_attr]
Someone please help. I have an interesting issue. I am trying to implement an
Please help me to sort multimap by the count of values. For example, multimap<char,int>
Please help me: I'm getting Error While using j4lOCR: `A fatal error has been
Please help me someone with this code. CSS Code #nav, #nav ul { width:1000px;
Please help me with this issue in my script. At the point of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.