开发者

Parser error with jquery ajax?

Here is my code it returns a parser error and fails.

$.ajaxSetup({
  type: 'GET',
  url: 'http://www.example.com/ajax',
  dataType: 'json'
});

$('#addHotlink').click(function() {
  $('body').after('<div id="lightBox" style="height: ' + htmlHeight + 'px;"><div><h3>Choose a name for your hotlink:<img id="lightBoxClose" src="http://www.example.com/images/closedAccordion.png" height="17" width="17" alt="" title="Close this box" /></h3><form id="addHotlinkForm" action="#" method="post" autocomplete="off"><input id="hotlinkName" type="text" maxlength="15" /><input class="submit" type="submit" value="Add Hotlink" /></form></div></div>');
  $('#lightBox').hide().fadeIn('fast');
  return false;
});

$('#addHotlinkForm').live('submit', function(event) {
  event.preventDefault();

  var pageURL = window.location.href;  
  var hotlinkName = $('#hotlinkName').val();

  if (hotlinkName.length > 0) {
    $.ajax({
      data: {
        hotlinkName: hotlinkName, 
        hotlinkURL: pageURL
      },
      success: function() {

        alert('Your hotlink ' + hotlinkName + ' has been inserted to the url: ' + pageURL);
      },
      error: function (ajaxOptions, thrownError) {

        alert(thrownError);
        alert('V开发者_Python百科ar hotlinkName: ' + hotlinkName + ' Var hotlinkURL: ' + pageURL);
      }
    });
  }
});

I get a parser error when it tries to execute? Although in the error function the values are being returned as:

hotlinkName: Text entered into box,

hotlinkURL: The current address of page (http://www.example.com/home)

Why is this not working? I have tried changing the type to POST and it still doesn't work?

Here is a fiddle of what I am trying to do, but of course it fails as it is not linked to any ajax sheet.

http://jsfiddle.net/novactown/QsDVe/


It worked for me, if you are using jsfiddle to test your script change the ajaxsetup to the following

$.ajaxSetup({

    type: 'GET',
        url: '/echo/json/',
    dataType: 'json'
});

I have created this : a simple environment to test ajax based javascript using JQuery on jsfiddle. You can checkout the jsfiddle documentation for more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜