jquery .ajax()问题 [英] jquery .ajax() issue
问题描述
我正在使用Jquery 1.7.1并且遇到了问题..我正在使用我的脚本中的CRM工作并且正在努力完成页面但我仍然坚持这个问题..
I am using Jquery 1.7.1 and am having issues.. I'm working with a CRM in my script and am working to get the page finished but I'm stuck with this issue..
我的html:
<form class="collector" action="https://www.domain.biz/admin/transact.php" method="POST">
<input type="hidden" name="method" value="NewProspect">
<input type="hidden" name="campaignId" value="3">
<input type="hidden" name="ipAddress" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>">
<fieldset>
<div style=" padding-left: 50px">
<table>
<tr>
<td><span style="color:red;">*</span>Your First Name:
<span id="rfvFirstName" style="display:none;">*</span>
</td>
<td><span style="color:red;">*</span>Your Last Name:
<span id="rfvFirstName" style="display:none;">*</span>
</td>
<td><span style="color:red;">*</span>Your Phone Number: </td>
<td><span style="color:red;">*</span>Primary Email: </td>
</tr>
<tr>
<td>
<input name="firstName" type="text" id="firstName" style="width:150px;" value="">
</td>
<td>
<input name="lastName" type="text" id="lastName" style="width:150px;" value="">
</td>
<td>
<input name="phone" type="text" id="phone" class="" style="width:150px;" value="">
</td>
<td>
<input name="email" type="text" id="email" class="required email" style="width:150px;" value="">
</td>
</tr>
</table>
</div>
<div class="clear"></div>
<center>
<input type="submit" name="continue" id="imgbtnSubmit" class="button" style="background-image: url('<?php echo base_url();?>inc/img/button-check.png');
background-repeat: no-repeat; width: 348px; height: 46px; border:none; background-color:transparent;" value="" />
</center>
</fieldset>
<p align="center" style="font-size:12px;">
</p>
</form>
JS:
$('.collector').submit(function(){
validate = true;
$(this).find("input:text:visible:enabled").each(function() {
if ($(this).attr("value") == "") {
alert("Please fill in all fields!");
$(this).focus();
validate = false;
return false;
}
else if ($(this).hasClass("email") && !$(this).attr("value").match(/@/)) {
alert("Please enter an email address...");
$(this).focus();
validate = false;
return false;
}
});
if (validate != false) {
$.ajax({
url: $(this).attr('action'),
type: 'POST',
data: $(this).serialize(),
success: function(response) {
alert(response);
}
});
}
return false;
});
现在这两件事都有效,而且它们很好地协同工作......问题在于我没有得到任何回应,我不知道为什么。我想这是因为萤火虫说的话...... POST https://www.domain.biz/admin/transact.php 200 OK 1.04s jquery.js(8102行)
Now both of these things work, and they work together fine... the issue comes in that I don't get any response and I'm not sure why. I imagine it is because of what firebug is saying... POST https://www.domain.biz/admin/transact.php 200 OK 1.04s jquery.js (line 8102)
我的firebug中的这一行显示为红色,jquery.js中的第8102行是: xhr.send((s .hasContent&& s.data)|| null);
This line in my firebug is displayed as red, and the line 8102 in jquery.js is: xhr.send( ( s.hasContent && s.data ) || null );
推荐答案
你做跨域ajax请求?我下载了你的代码并做了一个简单的测试:
Do you make an cross domain ajax request ? I downloaded your code and make a simple test:
代码在
- localhost :8080 / domain1 / a.php
向
- localhost:8080 / domain2 / b.php
发生错误
代码
- localhost:8080 / domain1 / a.php
向页面本身发出ajax请求
Make a ajax request to the page itself
- (localhost:8080 / domain1 / a.php)
没有错误发生并获得预期的响应。
然后我搜索了[ jquery.ajax跨域请求]的答案,找到一些链接可能会有所帮助:
jQuery AJAX跨域
Then I googled the answer for [jquery.ajax cross domain request],and find some links may helps: jQuery AJAX cross domain
$.ajax({
url:"testserver.php",
dataType: 'JSONP', // Notice! JSONP <-- P
success:function(json){
// do stuff with json (in this case an array)
alert("Success");
},
error:function(){
alert("Error");
},
});
这篇关于jquery .ajax()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!