使用vtiger webservices登录jquery

Using vtiger webserices to login with jquery

本文关键字:jquery 登录 webservices vtiger 使用      更新时间:2023-09-26

我有一个通过jquery使用webservices登录到vtiger crm的问题。这是我的代码:

function doLogin(){
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status === 200)
    {  
  alert(xmlhttp.responseText);
    }else{ 
        }
  }
xmlhttp.open("GET","http://vtiger_path/webservice.php?operation=getchallenge&username=admin",true);
xmlhttp.setRequestHeader("Content-type","json");
xmlhttp.send();
}

xmlhttp.status总是0,所以我没有收到警告

不能进行跨域Ajax调用(或者不容易…)

你不会用PHP吗?

下面是一个片段:

HTML/JS部分:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        var userName = 'admin';
        var webserviceUrl = 'http://vtiger_path/altaircrm/webservice.php';
        var action = "?operation=getchallenge&username=";
        var a = webserviceUrl+action+userName;
        $.ajax({
            url: "ws.php",
            type: 'POST',
            data:{'data':a},
            success: function(data) { alert(data); },
            error: function(data) { alert('Failed!'); },
        });
    });
});
</script>
</head>
<body>
<button>Send an HTTP request to a page and get the result back</button>
</body>
</html>
PHP部分:

<?php
 $a = $_POST['data'];
 $json = file_get_contents($a);
  echo $json;
?>