JSONP将数据发布到其他域

时间:2013-06-03 22:31:43

标签: jsonp

我试图通过搜索一段时间找到答案,但我找不到我需要的东西。

所以我有这些输入框。

  <div>
  Kontaktuppgifter<br>
  <input class="double" type="text" name="customer_firstName" placeholder="Förnamn" />
  <input class="double" type="text" name="customer_surName" placeholder="Efternamn" />
  <input class="double" type="email" name="customer_email" placeholder="Epost" />
  <input class="double" type="tel" name="customer_cellnr" placeholder="Mobilnummer" />
  </div>

  <div>      
  Adressuppgifter<br>
  <input type="text" name="customer_adress" placeholder="BostadsAdress" />
  <input type="text" name="customer_zipcode" placeholder="{{postal_code_label}}" />
  <input type="text" name="customer_city" placeholder="Ort" />
  <input type="text" name="customer_country" placeholder="Land" />
  </div>

  <div>
  Garantispecifika uppgfiter<br>
  <input type="text" name="customer_housenr" placeholder="Fastighetsbeteckning" />
  <input type="text" name="customer_persnumber" placeholder="Personnummer" />
  </div>

  <div>
  Företagsspecifika uppgifter - Fylls bara i av företag<br>
  <input type="text" name="customer_companyName" placeholder="Företagsnamn" />
  <input type="text" name="customer_Orgnr" placeholder="Organisationsnummer" />
  <input id="send_message" class="button secondary" type="submit" value="Registrera Garanti" onclick="postFrom(this)"/>
  </div>

现在我想通过 JSONP 发送所有数据。

我使用了一个属性'customer_name = json'

我应该如何连接所有内容以便将其发送给我的处理程序?

数据是我可以使用的唯一标记,或者我应该如何构建呼叫?

$.ajax({
   type: 'GET',
   url: 'http://www.mypage.com/offerthandler.ashx',
   crossDomain: true,
   data: 'customer_name=json',
   dataType: 'jsonp',
   success: function(responseData, jsonobj) {
   alert('POST Successfull.');

},
error: function (responseData, textStatus, errorThrown) {
    alert('POST failed.');
}
 });

我应该去找一个

 data: 'customer_firstName=$('[name="customer_firstName"]').val() + 
        customer_surName=$('[name="customer_surName"]').val()

等等或我怎么做?

1 个答案:

答案 0 :(得分:0)

执行此操作的简单方法是插入标记为表单提供id并序列化表单。

示例

 <form id="myform">

 Kontaktuppgifter<br>
 <input class="double" type="text" name="customer_firstName" placeholder="Förnamn" />
 <input class="double" type="text" name="customer_surName" placeholder="Efternamn" />
 <input class="double" type="email" name="customer_email" placeholder="Epost" />
 <input class="double" type="tel" name="customer_cellnr" placeholder="Mobilnummer" />
 </from>

现在javascript!

   var datavariable = $("#myform").serialize();

$.ajax({
type: 'GET',
url: 'http://yoururl.com',
crossDomain: true,
data: datavariable ,
dataType: 'jsonp',
success: function(responseData, jsonobj) {
    alert('POST Successfull.');

},