Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery是否可以使用带有基本http身份验证的ajax post?_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 使用jquery是否可以使用带有基本http身份验证的ajax post?

Javascript 使用jquery是否可以使用带有基本http身份验证的ajax post?,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有一个代码试图发布到api。但我在firefox和safari中分别获得了401和400分 $.ajax({ type: "POST", url: "http://url.com", dataType: "json", async: "false", data: form_data, beforeSend: function(xhr1) { xhr1.setReque

我有一个代码试图发布到api。但我在firefox和safari中分别获得了401和400分

      $.ajax({
        type: "POST",
        url: "http://url.com",
        dataType: "json",
        async: "false",
        data: form_data,
        beforeSend: function(xhr1) {
          xhr1.setRequestHeader("Authorization", "Basic " + encodeBase64(username + ":" + password))
        },
        success: function (data,status,xhr){
          //do something
        }
      });
我从这里遵照指示


*encodeBase64是库函数的一部分

使用Firebug或类似工具观察请求头。然后直接在网页中发出请求,而不使用XMLHTTPRequest。比较标题以找出差异。您是否希望使用
$.ajax
用户名
密码
属性?我也尝试了用户名和密码。在firefox中,我收到一个大错误
error:uncaughtexception:[exception…”成功参数1[nsIDOMDocumentXBL.getBindingParent]“nsresult:“0x0(NS_OK)”位置:“JS frame::chrome://global/content/bindings/tree.xml ::onxblunderflow::第947行“数据:否]
和safari使用相同的400个错误请求使用Firebug或类似工具观察请求头。然后直接在网页中发出请求,而不使用XMLHTTPRequest。比较标题以找出差异。您是否希望使用
$.ajax
用户名
密码
属性?我也尝试了用户名和密码。在firefox中,我收到一个大错误
error:uncaughtexception:[exception…”成功参数1[nsIDOMDocumentXBL.getBindingParent]“nsresult:“0x0(NS_OK)”位置:“JS frame::chrome://global/content/bindings/tree.xml ::onxblunderflow::第947行“数据:否”
和safari收到相同的400错误请求