我一直在尝试使用REST api从Dynatrace服务器获取XML响应。当我通过Postman放置url时,我可以轻松获得XML响应,并且我能够从ajax收到'xml'
数据类型响应,但不能收到function getXML() {
basicAuth = "Basic " + id + ":" + password;
$.ajaxSetup({
async: false
});
$.ajax({
type: 'GET',
url: dynUrl, //this is the function we defined above
dataType: 'xml',
headers: {
'Authorization': basicAuth //this is for basic authentication, you've already provided UID and PWD above.
},
//when we succeed, the function below will be called.
success: function(respt)
{
data = respt;
}
});
}
响应。我计划将这些数据解析为json以备将来使用。
我目前使用的代码是:
function XMLRespond()
{
getXML();
//dom = parseXml(data);
//json = xmlToJson(dom);
return data;
}
在以下函数中调用它。
data
Failed to open http://localhost:8080/api/Test.html
由localhost上托管的html调用并显示。但是,当我运行它时,我得到一个空白的屏幕,控制台说" Permission Denied"。我的调试器给了我:
{{1}}
非常感谢有关此问题的任何帮助!
答案 0 :(得分:0)
解决了这个问题。原来IE(我怀疑其他浏览器)无法直接显示public class chat_app extends AppCompatActivity{
InterstitialAd mInterstitialAd;
private InterstitialAd interstitial;
private Button btn_send_msg;
private EditText input_msg;
private TextView chat_conversation;
private String user_name,room_name;
private DatabaseReference root ;
private String temp_key;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat_room);
btn_send_msg = (Button) findViewById(R.id.btn_send);
input_msg = (EditText) findViewById(R.id.msg_input);
chat_conversation = (TextView) findViewById(R.id.textView);
user_name = getIntent().getExtras().get("user_name").toString();
room_name = getIntent().getExtras().get("room_name").toString();
setTitle(" Room - "+room_name);
root = FirebaseDatabase.getInstance().getReference().child(room_name);
btn_send_msg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Map<String,Object> map = new HashMap<String, Object>();
temp_key = root.push().getKey();
root.updateChildren(map);
DatabaseReference message_root = root.child(temp_key);
Map<String,Object> map2 = new HashMap<String, Object>();
map2.put("name",user_name);
map2.put("msg",input_msg.getText().toString());
message_root.updateChildren(map2);
}
});
root.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
append_chat_conversation(dataSnapshot);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
append_chat_conversation(dataSnapshot);
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private String chat_msg,chat_user_name;
private void append_chat_conversation(DataSnapshot dataSnapshot) {
Iterator i = dataSnapshot.getChildren().iterator();
while (i.hasNext()){
chat_msg = (String) ((DataSnapshot)i.next()).getValue();
chat_user_name = (String) ((DataSnapshot)i.next()).getValue();
chat_conversation.append(chat_user_name +" : "+chat_msg +" \n\n");
input_msg.setText("");
if(TextUtils.isEmpty(chat_msg)) {
Toast.makeText(this, "Empty field ", Toast.LENGTH_SHORT).show();
return;
}
}
`
。将data
转换为字符串会绕过此问题。