doudou521125 2016-04-30 13:43
浏览 197
已采纳

HTTP状态码0可能是跨站脚本?

I have a $.ajax that run file in php and pass a variable (email andress). The file works very good but the xhr.status is 0.

This is the code:

    $.ajax({
            type: 'POST',
            url: 'file.php',
            data: { email: destinatario },  
            complete: function(xhr,status){ 
            $('#momentaneo, #force').remove();
            alert(xhr.status);
                if(xhr.status ===  200){
                    alert('ok');                        
                }
                else{
                    alert('no');                        
                }
            }               
        });

This file.php, independently xhr.status, works fine and it add a user to my newsletter. So i don't think that this file is the problem.. It has "0755" permission files and if i run the url of file.php with browser there aren't problems.

The problem is that xhr.status is 0 and i don't understand why... I read that could be "cross-site-scripting" but i don't know if is possibile in my case. I tried also to change tag form in div but nothing.

I add also the file.php:

<?php
 include('wrapper.php');
 $apikey = "76a21109637d7391d1e68e9680e6";
 voxmail_init($apikey);
 voxmail_user_subscribe(array('mail' => $_POST['email'],'privacy' => 1),$_SERVER['REMOTE_ADDR']);

 $header = "Content-type: text/html";
 header($header);
 print('<b>ok</b>');
?>

voxmail are API of newsletter service (i'm sure 101% that api are not problem)

i hope can you help me, thank a lot and sorry for my english

  • 写回答

1条回答 默认 最新

  • douru5373 2016-04-30 14:32
    关注

    I think the problem is that you're checking xhr.status when status is being passed to you as the second parameter in your complete callback. Try this instead:

    $.ajax({
      type: 'POST',
      url: 'file.php',
      data: { email: destinatario }
    }).always(function(){
      $('#momentaneo, #force').remove();
    }).then(function(){
      console.log.apply(console, arguments);
      alert('ok');
    }, function(){
      console.warn.apply(console, arguments);
      alert('no');
    });
    

    The console statements are only there for debugging purposes and can be removed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏