如何获得回应 [英] how to get a response

查看:110
本文介绍了如何获得回应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
被困在一个问题上了两天.问题是我试图从本地主机访问Web服务.
出于测试目的,我编写了这段代码,它按照应有的方式运行:

Hello guys ,
Stuck at a problem for two days . The problem is that i am trying to hit a webservice from localhost .
Just for testing purposes i wrote this code and it ran the way it was supposed to :

<a href="http://www.zipdial.com/z2v/startTransaction.action?customerToken=mycustomertoken&clientTransactionId=1&callerid=9968280904&duration=180&countryCode=91&z2vToken=another_token">Save</a>


如您所见,所有内容都是静态的,并且像魅力一样起作用,因为我在浏览器中看到了类似的内容:
{"message":"ok","client_transaction_id":"2","transaction_token":"sometoken","status":"1","img":"http://www.zipdial.com/zip2auth/images/access/b8b7ad5781c6f07b775f623ab62f4f8d34f81570}
现在我需要从中提取img元素,但是我不知道该如何处理.
我试过像这样使用jquery:


As you can see , everything is static and it works like a charm because i see something like this on the browser :
{"message":"ok","client_transaction_id":"2","transaction_token":"sometoken","status":"1","img":"http://www.zipdial.com/zip2auth/images/access/b8b7ad5781c6f07b775f623ab62f4f8d34f81570"}
Now i need to extract the img element from it but i have no idea in how to go about it .
I tried using jquery like this :

$(document).ready(function() {
     
		 alert('hello');

		 $.getJSON("http://www.zipdial.com/z2v/startTransaction.action?customerToken=mycustomertoken&clientTransactionId=2&callerid=9968280904&duration=180&countryCode=91&z2vToken=another_token",function(jd)
		{
			alert("hello again");
             alert(jd.image);
             
          });
	});


现在,我只看到一个alert("hello")弹出窗口,但是在函数调用中什么都没有,在我的浏览器中我看到了这个
"起源http://server_name不受Access-Control-Allow-Origin的限制."
请帮助


Now i only see the alert("hello") as a pop up but nothing inside the function call and on my browser i see this
"Origin http://server_name is not allowed by Access-Control-Allow-Origin."
Please help

推荐答案

(文档).ready(功能(){ alert(' 你好');
(document).ready(function() { alert('hello');


.getJSON(" " ); 警报(jd.image); }); });
.getJSON("http://www.zipdial.com/z2v/startTransaction.action?customerToken=mycustomertoken&clientTransactionId=2&callerid=9968280904&duration=180&countryCode=91&z2vToken=another_token",function(jd) { alert("hello again"); alert(jd.image); }); });


现在,我只看到一个alert("hello")弹出窗口,但是在函数调用中什么都没有,在我的浏览器中我看到了这个
"起源http://server_name不受Access-Control-Allow-Origin的限制."
请帮助


Now i only see the alert("hello") as a pop up but nothing inside the function call and on my browser i see this
"Origin http://server_name is not allowed by Access-Control-Allow-Origin."
Please help


正如我所看到的,这是一个跨域调用.因此,简单的getJSON是不够的.查阅旧版 ajax [ ^ ]方法来查看如何设置JSONP调用的参数.
As I see, this is a cross-domain call. Thus a simple getJSON won''t be enough. Consult the legacy ajax[^] method to see how you have to set parameters for a JSONP call.


这篇关于如何获得回应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆