weixin_33674976 2014-12-12 14:35 采纳率: 0%
浏览 46

使用Post进行Web服务调用

I am new to webservice and ajax .. I tried to call a webservice using POST method. I tried to invoke it using Postman (Google chrome App) and I was getting the response but when I tried using Ajax I am getting error Following are the things I did:

My Code: (I wrote a JS in which I included following code and tried all the commented options too ):

$.ajax({
    crossDomain: true,
    url : 'https://yxyxyxyxyx/search/v1/query.json', 
    type : 'POST',
    dataType : "json",
    data: {appId: "a9b475a079",query: "dhcp"},
    //async : true,
    //headers: {"Content-type": "application/json"},
    headers: { 'Access-Control-Allow-Origin': '*' },
    //contentType: "application/json; charset=utf-8",
    //headers: ('Access-Control-Allow-Methods: GET, POST, OPTIONS'),
    //headers: ('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With'),
    //headers: ('Access-Control-Allow-Credentials: true'),
    // Access-Control-Allow-Origin: "http://localhost:8080",
    // headers: { 'Access-Control-Allow-Origin': '*' },
    //userAgent : 'Mozilla/22.0',

    success: function(data){

     alert("hi success");
    },
    error: function(data) {alert("An error occured: " + data.status + " " + data.statusText);
    });

I am getting the alert in the error and getting following error while debugging:

XMLHttpRequest cannot load https://www.sample.search/v1/query.json. The request was redirected to 'https://www.sample/obrareq.cgi?wh%3DCCI-STG4%20wu%3D%2Fuesps%…n-tools-stage.cisco.com%20ru%3D%252Fuesps%252Fsearch%252Fv1%252Fquery.json', which is disallowed for cross-origin requests that require preflight.

I tried all the options to resolve the CROS option in which I found on net… do we have any other way to resolve it.

Can someone help me if we can do it using a java class that will also serve the purpose

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料