简体   繁体   English

使用Ajax Codeigniter跨域的Ajax POST

[英]Ajax POST Using Ajax Codeigniter Cross Domain

I want to explain first ... 我想先解释一下...

I have two domain .. www.one.com and www.two.com 我有两个域.. www.one.com和www.two.com

First domain www.one.com Form input here 第一个域名www.one.com此处输入表格

<div class="hidden cswrap2">
  <h3>Edit Data Mustahik</h3>
  <div class="cscontent">
    <ul class="cslist">
      <li id="">
      <form  action="javascript:void(0);" name="editmustahik">
        <div style="margin-bottom: 10px; width: 230px;">  
            <label>Kuantitas</label>
            <input type="text" name="kuantitas" value="<?php echo @$mpzis['kuantitas'];?>" style="width:230px;">
            <input type="text" name="nik" value="<?php echo @$mpzis['nik'];?>" style="width:230px;">
            <input type="text" name="amil_email" value="<?php echo @$mpzis['email_amil'];?>" style="width:230px;">
        </div>
      </form>
    </li>
  </ul>
  </div>
  <div class="csbutton">
    <input type="button" name="buttonstatus" onclick="hideCustomStatus('cswrap2');" value="Batal" id="customstatusbutton">&nbsp;
    <input type="submit" onclick="UpdateDataMustahik();" value="Update">
  </div>
 </div>

this ajax post 这个ajax帖子

function UpdateDataMustahik() {
    var formData = $('form[name="editmustahik"]').serialize();

    displayCustomStatus('Update Data Mustahik');
    addCustomStatusContent('Updating Data','update777');
    $.ajax({
      url: 'www.two.com/api_controller/update',
      type: 'POST',
      dataType: 'json',
      data: formData,
      success: statusUpdate
    });
}

function statusUpdate(json) {
  if(json.status_code == '000') {
      addCustomStatusContent('Sukses','update777');
    }
}

i have second domain to direct there .. www.two.com/api_controller/update --> url: 'www.two.com/api_controller/update', 我有第二个域名直接指向.. www.two.com/api_controller/update->网址:“ www.two.com/api_controller/update”,

in controller i was put this code 在控制器中,我把这段代码

  header('Access-Control-Allow-Origin: *');
  header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");

but still not working .. error display is 404 not found .. 但仍然无法正常工作..错误显示找不到404。

may you know how to solve this .. 也许你知道如何解决这个问题..

Thanks 谢谢

Try 尝试

    $.ajax({
            url: url
            //dataType: 'json',
            type: 'POST',
            xhrFields: {
                withCredentials: true
            },
            crossDomain: true,
            data: {data:data},
            success: function (data) {
//your code
} });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM