相关疑难解决方法(0)

jQuery ajax成功错误

我正在尝试提交一份表格女巫发送电子邮件:

JS

var that = $(this);
$.ajax({
  url: '../wp-content/themes/bsj/php/validate.php',
  type: 'post',
  context: that,
  data: $('#sign-up').serialize(),
  cache: false,
  success: function(){ 
    alert('success!');
  },
  error: function(){
    alert('error!');
  }
});
Run Code Online (Sandbox Code Playgroud)

PHP

/*----------------------------------
    Variables
----------------------------------*/

    // Personal info
    $prefix = $_POST['prefix'];
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $company = $_POST['company'];
    $email = $_POST['email'];
    $title = $_POST['title'];
    $dept = $_POST['dept'];

    // Contact details
    $address = $_POST['address'];
    $address2 = $_POST['address2'];
    $city = $_POST['city'];
    $state = $_POST['state'];
    $zip = $_POST['zip'];
    $phone = $_POST['phone'];
    $ext = $_POST['ext'];
    $fax = …
Run Code Online (Sandbox Code Playgroud)

ajax jquery

13
推荐指数
1
解决办法
10万
查看次数

跨域AJAX请求无效

我在第三方API上调用POST,我一直在使用jQuery的$ .ajax函数.但是,当我拨打电话时,我收到以下错误:XMLHttpRequest cannot load http://the-url.com. The request was redirected to 'http://the-url.com/anotherlocation', which is disallowed for cross-origin requests that require preflight.

我在这篇文章中看到这可能是一个Webkit错误,所以我在Firefox中尝试过它(我在Chrome中开发)并得到了相同的结果.我在Chrome和Firefox上尝试了这个,我得到了相同的结果.

根据这篇文章,我也尝试使用jsonp crossDomain将$ .ajax函数的属性true设置为并设置dataTypejsonp.但是,这导致500内部服务器错误.

当我使用--disable-web-security标志启动Chrome时,我没有任何问题.但是,如果我正常启动浏览器,那么我会收到错误.

所以,我想这可能是一个由两部分组成的问题.我该怎么做才能提出这个跨域请求?如果答案是JSONP,那么我该如何确定第三方API是否设置正确以支持这一点?

编辑:这是我在禁用浏览器安全性的情况下拨打电话的屏幕截图:https://drive.google.com/file/d/0Bzo7loNBQcmjUjk5YWNWLXM2SVE/edit?usp =sharing

这是我在启用浏览器安全性的情况下拨打电话时的屏幕截图(正常情况下):https://drive.google.com/file/d/0Bzo7loNBQcmjam5NQ3BKWUluRE0/edit?usp=sharing

ajax jquery jsonp cross-domain cors

13
推荐指数
2
解决办法
4万
查看次数

跨域ajax请求

我想从跨域url获取html响应页面.

为此,我使用ajax请求,因为,

 $.ajax({
            type: 'GET',
            url: "http://wcidevapps.com/salescentral/idisk/0001000383/iDisk",
            dataType: "jsonp",
            success: function (response) {
                $(response).find('li a').each(function () {
                    listHref.push($(this).attr('href'));
                });

            }
        });
Run Code Online (Sandbox Code Playgroud)

但在请求后它没有回复任何结果.

html ajax jquery asp.net-ajax

12
推荐指数
2
解决办法
7万
查看次数

使用.getJSON获取Play Store应用程序详细信息时出现Cross Origin Block Request [CORS]错误

所以基本上我使用42matters.com APP市场API从谷歌游戏商店获取应用程序详细信息或信息,一切正常,我收到了JSON回复,但当我周末假期后回到办公室时,这个相当奇怪的错误来了,没有任何东西被退回.

我使用了$ .getJSON函数,如:

var packageID = 'com.whatsapp';
   $.getJSON('https://42matters.com/api/1/apps/lookup.json?p='+packageID+'&access_token=accesstoken1234')
.done(function(appDetails) {
            $('#logo').html(JSON.stringify(appDetails));
        });
Run Code Online (Sandbox Code Playgroud)

如上所述,这是返回数据,我能够相应地改变一切,但现在它无缘无故地给了我这个错误

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://42matters.com/api/1/apps/lookup.json?p=com.whatsapp&access_token=accesstoken1234. This can be fixed by moving the resource to the same domain or enabling CORS
Run Code Online (Sandbox Code Playgroud)

我已经使用PHP启用了CORS,没有任何问题,尝试更改apache的conf文件以启用CORS,但服务不会重启,所以我被卡住了.

还有一件事,当我在浏览器中手动输入上述链接时,它确实提供了所需的结果.请帮我解决一下

javascript php apache ajax cors

7
推荐指数
2
解决办法
8万
查看次数

使用jsonp错误的jQuery ajax请求

我正在编写一个应用程序,我需要从另一台服务器访问客户端的一些json数据.由于跨域问题,我计划使用jsonp.jQuery允许我使用$ .getJSON()方法执行此操作,但是,我无法判断方法是否已失败(即服务器没有响应或其他内容).所以我尝试使用$ .ajax来获取JSON数据.但它不起作用,我不知道该尝试什么.这是一个显示我的问题的示例:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
      <meta http-equiv="Content-type" content="text/html; charset=utf-8">
      <title>TEST</title>
      <script type="text/javascript" src="scripts/jquery-1.5.1.min.js"></script>
      <script type="text/javascript">
           $(document).ready(function() {
        $('#button_detect').click(function(){
            var feedApiAjax = 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=';
            var feedApiGetJSON = 'http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&callback=?&q=';
            var feedUrl = 'http://www.engadget.com/rss.xml';

            $.ajax({
                url: feedApiAjax + feedUrl,
                datatype: 'jsonp',
                success: function(data) {
                    console.log('$.ajax() success');
                },
                error: function(xhr, testStatus, error) {
                    console.log('$.ajax() error');
                }
            });

            $.getJSON(
                feedApiGetJSON + feedUrl,
                function(data) {
                    console.log('$.getJSON success');
                });
        });
    });
      </script>
 </head>
 <body>
      <div id="button_detect">CLICK ME!!!!</div>
 </body>
Run Code Online (Sandbox Code Playgroud)

如果您使用此代码创建一个网页并单击"Click Me"div,您将看到$ .getJSON请求正在运行而$ …

ajax jquery json jsonp

6
推荐指数
2
解决办法
2万
查看次数

SyntaxError:检索JSON对象时无效的标签

检索JSON对象时收到以下错误:

  1. SyntaxError:Mozilla中的无效标签.
  2. 未捕获的SyntaxError:意外的令牌:在Chrome中

我的JSON对象是如下所示的格式:

{
   "userName" : "clevermeal835",
   "userRole" : "Participant",
   "userAccountStatus" : "Active"
}
Run Code Online (Sandbox Code Playgroud)

码:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="Scripts/jquery-min.js"></script>
<script src="Scripts/jquery_validate.js"></script>
<script>
$(document).ready(function() {
    loadLatestTweet();  
});

function loadLatestTweet(){
var xhr = new XMLHttpRequest();
var uid = "clevermeal835";
var pwd = "Welcome_1";
var userType = "participant";
    var surl =      'http://localhost:8080/RESTlet_WS/MobiSignIn/{"userName":"'+uid+'","password":"'+pwd+ '","userType":"'+userType+'"}&callback=?';

    var jqxhr = $.getJSON(surl, function() {
        alert("success");
    }).success(function() { alert("second success");   }).error(function() { alert("error"); }).complete(function() { alert("complete"); });
    jqxhr.complete(function(){ alert("second complete"); });
 }
 </script>
</head> …
Run Code Online (Sandbox Code Playgroud)

javascript jquery json

6
推荐指数
1
解决办法
9778
查看次数

如何通过Jquery获取页面打开图元数据

用户可以在我的网站上的文本框中粘贴网址.当他们这样做时,我想通过jQuery AJAX获取该URL并从中读取opengraph元数据.我怎样才能做到这一点?

我读过这篇文章如何从带有网址的网页上阅读Open Graph和meta标签,但其中的链接被破坏,它比我需要的更高级,而不是在jQuery :)

除了opengraph元数据之外我不需要任何其他内容,因此不需要解析结构等.

以下是页面示例:http://www.ebay.com/itm/Microsoft-Surface-Pro-3-12-Tablet-256GB-SSD-Intel-Core-i7-Haswell-8GB-RAM-/281656969697

因此,我想提取的其中一个领域<meta property="og:image" content="http://i.ebayimg.com/images/i/281656969697-0-1/s-l1000.jpg" ></meta>,确切地说是价值http://i.ebayimg.com/images/i/281656969697-0-1/s-l1000.jpg

我现在拥有的是从这里复制的:http://icant.co.uk/articles/crossdomain-ajax-with-jquery/error-handling.html

请参阅我的评论@Flo,我想要提取打开的图形数据,但我不知道如何解析JSON响应.

<a href="www.ebay.com/itm/Microsoft-Surface-Pro-3-12-Tablet-256GB-SSD-Intel-Core-i7-Haswell-8GB-RAM-/281656969697" class="ajaxtrigger">Load Ajax Content</a>
<div id="target"></div>

    <script language="javascript" type="text/javascript">
    $(function () {

        $('.ajaxtrigger').click(function () {
            var container = $('#target');
            container.attr('tabIndex', '-1');
            var trigger = $(this);
            var url = trigger.attr('href');
            if (!trigger.hasClass('loaded')) {
                trigger.append('<span></span>');
                trigger.addClass('loaded');
                var msg = trigger.find('span').last();
            } else {
                var msg = trigger.find('span').last();
            }
            doAjax(url, msg, container);
            return false;
        });
    });


    function doAjax(url, …
Run Code Online (Sandbox Code Playgroud)

ajax jquery open-graph-protocol

6
推荐指数
1
解决办法
3265
查看次数

AJAX提交和500服务器错误

尝试运行我的AJAX时出现500服务器错误.我是AJAX的新手.如果我在脚本中没有运行AJAX,那么每个东西都在代码中运行,例如只运行:

$("#book-appointment-form").submit();

因此,似乎所有数据库功能都很好.但是,我需要AJAX在Wordpress页面中运行我的代码.

我没有在错误日志中看到任何注释.控制台日志显示该URL指向正确的位置.我可能缺少什么?

控制台日志显示hiddenData中显示的隐藏输入中的数据:

0: Object
name: "csrfToken"
value: "0f4343dfd0e71a8fa515d08f340f7bc9"
__proto__: Object
1: Object
name: "post_data"
value: "{"customer":{"last_name":"Test","first_name":"Joe","email":"email4me@verizon.net","phone_number":"9093334444","address":"","city":"","zip_code":"","id_cellcarrier":"2","wp_id":"1"},"appointment":{"start_datetime":"2015-12-25 11:00:00","end_datetime":"2015-12-25 11:50:00","notes":"","is_unavailable":false,"id_users_provider":"85","id_services":"13"},"manage_mode":false}"
__proto__: Object
length: 2
__proto__: Array[0]
Run Code Online (Sandbox Code Playgroud)

视图:

<html>

                    <form id="book-appointment-form" style="display:inline-block" method="post">
                        <button id="book-appointment-submit" type="button">Confirm</button>
                        <input type="hidden" name="csrfToken" />
                        <input type="hidden" name="post_data" />
                    </form>
</html>
Run Code Online (Sandbox Code Playgroud)

JS

<script>
                $("#book-appointment-form").submit(function(event){
                    var confirmedData = $(this).serializeArray();
                    var dataUrl = GlobalVariables.baseUrl + '/index.php/appointments/ajax_confirm_appointment'; 
                    $.post(dataUrl, confirmedData, function(response) {
                    ////////////////////////////////////////////////////////////
                    console.log('Customer Confirmed Post Response:', response);
                    ////////////////////////////////////////////////////////////
                    }, 'json');
                    event.preventDefault();
                });
                $("#book-appointment-form").submit();
</script>
Run Code Online (Sandbox Code Playgroud)

PHP控制器

<?php
public function …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax wordpress jquery

5
推荐指数
1
解决办法
1024
查看次数

使用ADAL通过Angular 2对Dynamics CRM Web API进行未经授权的HTTP请求

我正在尝试使用Angular创建一个可以通过Web API连接到Dynamics CRM的应用程序.这些是我遵循的步骤:

1.在Azure中注册本机应用程序,授予所需的委派权限并更新清单以允许隐式流.

2.在CRM中创建应用程序用户,将其应用程序ID设置为等于我的Azure注册应用程序的客户端ID.为我的应用程序用户分配了自定义安全角色.

3.克隆了许多Angular 2快速启动Git存储库,这些存储库通过ADAL(例如 ADAL)通过Azure AD进行身份验证.

4.更新了克隆代码的阿达尔配置,设置我的tenant,clientId,redirectUriendpoints.

到目前为止,这已经成功了.我可以通过我的浏览器启动应用程序并登录,作为我的应用程序用户或作为Azure AD一部分的其他CRM用户.这会返回一个令牌.

5.尝试发送http.get要么v8.0v8.2(有人告诉我v8.2不支持跨域调用的):

getEntities(): Promise<any> {
    let token = this.adalService.getCachedToken(this.adalService.config.clientId);
    let headers = new Headers({
        'Authentication': 'Bearer ' + token,
        'Accept': 'application/json',
        'Content-Type': 'application/json; charset=utf-8',
        'OData-MaxVersion': '4.0',
        'OData-Version': '4.0'
    });
    let options = new RequestOptions({ headers: headers });

    return this.http.get(`${crmURL}/api/data/v8.2/accounts`, options)
        .toPromise()
        .then((res) => { return res; }) …
Run Code Online (Sandbox Code Playgroud)

dynamics-crm azure azure-active-directory adal angular

5
推荐指数
1
解决办法
1212
查看次数

ajax 调用中的作用域变量

为什么最终的控制台日志是未定义的?变量时间具有全局范围,并且ajax调用是异步的。

这是我的代码:

var time;
$.ajax({
    async:"false",
    type: 'GET',
    url: "http://www.timeapi.org/utc/now.json",
    success: function(data) {
        console.log(data);  
        time=data;
    },
    error: function(data) {
      console.log("ko");
    }
});
     
console.log(time);  
Run Code Online (Sandbox Code Playgroud)

javascript ajax

3
推荐指数
1
解决办法
4659
查看次数