ajax发送了requet,但是得到了err_empty_response

时间:2018-09-07 07:04:52

标签: javascript http

最近,我输入了有关err_empty_response的问题。我向服务器发送了ajax请求,但收到了err_empty_resonse的响应。这是代码:

$.ajax("/wordpress/api/sync_agent_and_estate/", {
    success: function(data){
        if(data['status'] == 'success'){
            //start to sync up agent and property
        else{                                                                                                                                                                 55,1          12%


            alert('Failed to sync: ' + data['message']);
        }
    },
    error: function(data){
        alert('Failed to sync properties and agents.');
    }
});

chrome较早获得了err_empty_reponse,但是服务器仍然执行。 该请求可能花费了1-2分钟。 请帮助我,谢谢。

这是后端代码:

@company_login_required
def sync_agent_and_estate_view(request):
company = get_current_company(request)
domain_url = company.get_wordpress_domain()
wp_client = WordPressClient('http://' + domain_url + '/xmlrpc.php',
                            settings.WORDPRESS_USERNAME,
                            settings.WORDPRESS_PASSWORD)

post_user = get_wp_user(wp_client, company)

# Check account has been activiated and theme set to wp-residence
check_result = check_wp_client(wp_client, company)
if check_result and check_result["status"] == "failed":
    return json_response(check_result)

# Sync estates and agents
agent_list = cmsUser.objects.filter(company=company.id)
agent_post_dict = get_agent_post_dict(wp_client)
estate_post_dict = get_estate_post_dict(wp_client)

for agent in agent_list:
    existed_agent_post = agent_post_dict.get(str(agent.id), None)
    agent_post = sync_agent(
        wp_client, agent, existed_agent_post, post_user)

    # If the property is in-activated, it should be synced to wordpress too
    estate_list = estate.active_estate.filter(owner=agent)
    # Do a batch update of RETS GPS query first
    mls_list = estate_list.values_list("mls_number", flat=True)
    mls_list = list(mls_list)

    rets_gps_dict = {}

    rets_query_url = "http://" + settings.APICENTER_DOMAIN + \
                     "/idx/estate_search_by_mls/?type=map" + \
                     "&listing_id_list=" + ",".join(mls_list) + \
                     "&mred_region=" + settings.MRED_REGION + \
                     "&listing_office_id=" + company.company_office_id

    result = wp_common_request(rets_query_url)
    for item in result:
        rets_gps_dict[item["mls_number"]] = (item["LAT"], item["LNG"])

    geocoder = Geocoder()
    for estate_item in estate_list:
        coordinate = rets_gps_dict.get(estate_item.mls_number, None)
        if not coordinate:
            coordinate = get_coordinate_for_estate(estate_item, geocoder)

        estate_post = estate_post_dict.get(str(estate_item.id), None)
        sync_estate(wp_client, estate_item, estate_post,
                    agent_post, post_user, coordinate)

return json_response({"status": "success"})

0 个答案:

没有答案