2012-05-15 44 views
0

更新jQuery的AJAX表单提交的问题 - 表单数据提交,但返回错误不是成功

从提琴手2:

我可以看到发送的数据。他们也出现在其他网站的数据库中。

从其他域/服务器的响应似乎不正确:

Response sent 38 bytes of Cookie data: 
Set-Cookie: ARPT=YOLMQLS172.25.102.96CKMYK; path=/ 

This response did not contain a P3P Header. 

是否可以安全使用,即使标头响应不正确,此实现继续吗?

我使用jquery validate plugin验证我的表单,然后jquery ajax将表单数据发布到外部网站(Marketo潜在客户平台)。

表单数据已成功提交到外部网站(Marketo)。我通过登录他们的网站验证了这一点,我可以看到我提交的测试表单帖子与所有的现场数据。

但是,我从ajax调用得到一个错误,而不是成功响应。

这是代码 - 任何想法?

$(feedbackForm).validate(
{ 
    validClass: "success", 
    rules: 
    { 
     FirstName: { required: true }, 
     LastName: { required: true }, 
     Email: 
     { 
      required: true, 
      email: true         
     }, 
     Question__c: { required: true } 
    }, 
    messages: 
    { 
     FirstName: "Please enter your first name", 
     LastName: "Please enter your last name", 
     Email: "Please enter a valid email address", 
     Question__c: "Please enter your message" 
    },  
    submitHandler: function(form) 
    {    
     $.ajax(
     { 
      type:"POST", 
      url: "http://app-k.marketo.com/index.php/leadCapture/save",     
      data: feedbackForm.serialize(), 
      success: function(response) 
      { 
       feedbackForm.find('.form_result').html(response.statusText); 
       alert('success'); 
      }, 
      error: function(response) 
      { 
       feedbackForm.find('.form_result').html(response.statusText);      
       alert("error"); 
      } 
     }); 
     return false;   
    } 
+0

http://app-k.marketo.com/index.php/leadCapture/save返回什么?在'error'函数中,如果你是console.log(response) - 那会返回什么?如果你要返回一个JSON数组,你可能只需要在你的AJAX函数中传递dataType:'json'。 –

+0

Alert'$('#easycopyFeedbackForm')。serialize()'看看弹出了什么 – Norse

+0

console.log(response)返回一堆东西,比如statusText =“error”。我不知道如何从对象中知道它是否返回json,但我尝试过dataType:'json'并且仍然是这样。 – IntricatePixels

回答

0

您似乎对不在您自己的域中的url发出ajax请求,该域通常由于跨域访问限制而受到限制。

如果它实际上不在您的域上,则需要通过服务器端语言向该服务器发出请求。 ajax会调用代码,然后再调用其他调用。

但是,如果他们允许公众从外部域访问该URL,那么我所说的是无关紧要的。

+0

Kristian,该网址不在我的域名中,是的,所以也许您位于正确的区域。我在一个.net应用程序,所以需要弄清楚如何使呼叫服务器端。 – IntricatePixels

+0

但也想知道,如果这是真的,它如何将数据发布到外部网站?或者它是由于跨域问题而不能回复的响应消息? – IntricatePixels

+0

有一种明显的可能性,即他们将该URL用于公共API,并且允许跨域请求访问该URL。它只取决于他们 – Kristian