我想进行一项更改用户配置文件的活动。接收到的基于JSON的部分正常运行。我已经在PHP代码中手动测试了set变量。但是,当我将变量从android发布到php时,它无法接收它。有人可以告诉我问题吗?
import {
users
} from "../models/main.js"
const myRanking = document.querySelector("#usersRank")
renderRankings();
function renderRankings(){
let result3 = ""
for(const user of users) {
result3 += `
<div>
<style>
table, th, td {
border: 1px solid green;
border-collapse: collapse;
}
</style>
<table style="width:50%">
<tr>
<th>Nome</th>
<th>XP</th>
</tr>
<tr>
<td>${user.username}</td>
<td>${user.xp}</td>
</tr>
</table>
</div>
`
myRanking.innerHTML = result3;
}
}
答案 0 :(得分:0)
有同样的问题无法弄清楚问题出在哪里,但这可以解决问题,请不要忘记在gradle文件中添加依赖项
import networkx as nx
from collections import defaultdict
G = nx.karate_club_graph()
avg_neigh_degrees = nx.algorithms.assortativity.average_neighbor_degree(G)
deg_to_avg_neighbor_degrees = defaultdict(list)
for node, degree in nx.degree(G):
deg_to_avg_neighbor_degrees[degree].append(avg_neigh_degrees[node])
# this is the same as nx.algorithms.assortativity.average_degree_connectivity(G)
avg_degree_connectivity = {degree: sum(vals)/len(vals) for degree, vals in
deg_to_avg_neighbor_degrees.items()}
**实现'com.he5ed.lib:volley:android-cts-5.1_r4' **
答案 1 :(得分:0)
尝试如下修改您的loadProifle()方法
// define below variable to globally
String mRequestBody=null;
private void loadProfil() {
try {
JSONObject jsonBody = new JSONObject();
jsonBody.put("namekey", "paste here name");
jsonBody.put("emailkey", "paste here email");
jsonBody.put("passkey", "paste here password");
jsonBody.put("nokey", "paste here number");
mRequestBody = jsonBody.toString();
}catch(JSONException e){
e.printStackTrace();
}
StringRequest stringRequest = new StringRequest(Request.Method.POST, PROFIL_URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONArray profil = new JSONArray(response);
JSONObject profilObject = profil.getJSONObject(0);
String foto_user = profilObject.getString("foto_user");
String username = profilObject.getString("username");
String email = profilObject.getString("email");
String password = profilObject.getString("password");
String nohp = profilObject.getString("nohp");
Profil viewProfil = new Profil(foto_user, username, email, password, nohp);
profilList.add(viewProfil);
editTextNama.setText(username);
editTextEmail.setText(email);
editTextPassword.setText(password);
editTextNohp.setText(nohp);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(ProfilActivity.this, error.getMessage() + "Error Load Profil", Toast.LENGTH_LONG).show();
}
}){
@Override
public byte[] getBody() throws AuthFailureError {
try {
return mRequestBody == null ? null : mRequestBody.getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}
};
Volley.newRequestQueue(this).add(stringRequest);
}
答案 2 :(得分:0)
这是我的PHP代码,用于获取电子邮件变量。 有什么问题吗?
<?php
define('DB_HOST','Localhost');
define('DB_USER','id9815170_phpjember');
define('DB_PASS','phpjember');
define('DB_NAME','id9815170_phpjember');
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(mysqli_connect_errno()){
die('Unable to connect to database ' . mysqli_connect_error());
}
$email = $_POST['email'];
$stmt = $conn->prepare("SELECT foto_user, username, email, password, nohp FROM datauser WHERE email='$email';");
$stmt->execute();
$stmt->bind_result($foto_user, $username, $email, $password, $nohp);
$profil = array();
while($stmt->fetch()){
$temp = array();
$temp['foto_user'] = $foto_user;
$temp['username'] = $username;
$temp['email'] = $email;
$temp['password'] = $password;
$temp['nohp'] = $nohp;
array_push($profil, $temp);
}
echo json_encode($profil);
?>